Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified.
Source code:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(void) {
char title[50];
char col1[50];
char col2[50];
int point[50];
char names[50][50];
printf("Enter a title for the data:\n");
fgets (title, 50, stdin);
printf("You entered: %s\n", title);
printf("Enter the column 1 header:\n");
fgets (col1, 50, stdin);
printf("You entered: %s\n", col1);
printf("Enter the column 2 header:\n");
fgets (col2, 50, stdin);
printf("You entered: %s\n", col2);
col1[strlen(col1) - 1] = '\0';
col2[strlen(col2) - 1] = '\0';
int count = 0;
char dataPoint[50];
while (count < 50) {
printf("Enter a data point(-1 to stop input):\n");
fgets (dataPoint, 50, stdin);
if (atoi(dataPoint) == -1) {
exit(0);
}
int commas = 0;
int i = 0;
int intFound = 0;
char integerValue[5] = "";
int commaAfterInt = 0;
while (dataPoint[i] != '\0') {
if (dataPoint[i] == ',') {
commas++;
if (intFound == 1) {
commaAfterInt = 1;
}
} else if (commas == 0) {
names[count][i] = dataPoint[i];
} else if (isdigit(dataPoint[i])) {
intFound = 1;
int j = 0;
for (j = 0; integerValue[j] != '\0'; j++);
integerValue[j] = dataPoint[i];
integerValue[j + 1] = '\0';
}
i++;
}
if (commas == 0) {
printf("Error: No comma in string.\n");
} else if (commas > 1) {
printf("Too many commas in input.\n");
} else if (commaAfterInt == 1) {
printf("Comma not followed by an integer\n");
} else {
point[count++] = atoi(integerValue);
}
}
printf("FORMATTED TABLE");
printf("%33s", title);
//printf("%23s", col1);
printf("%23s | %20s",col1,col2);
printf("\n
-----------------------------------------------------\n");
int i = 0;
// printf("Count:%d\n",count);
while (i < count) {
printf("%23s | %20d", names[i], point[i]);
i++;
}
printf("FORMATTED HISTOGRAM");
i = 0;
while (i < count) {
printf("\n%28s ", names[i]);
int j = 0;
while (j < point[i]) {
printf("*");
j++;
}
printf("\n");
i++;
}
return 0;
}
Here are the expected answers and inputs to the program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char title[255];
printf("Enter a title for the data: ");
scanf("%[^\n]s", title);
printf("You entered: %s\n\n", title);
char col1[255], col2[255];
printf("Enter the column1 header: ");
scanf("\n%[^\n]s", col1);
printf("You entered: %s\n", col1);
printf("Enter the column2 header: ");
scanf("\n%[^\n]s", col2);
printf("You entered: %s\n\n", col2);
char data[255], data_str[100][255];
int data_int[100];
int i = 0;
// while (1)
// {
// printf("Enter a data point(-1 to stop input):");
// scanf("\n%[^\n]s", data);
// if (strcmp(data, "-1") == 0)
// {
// break;
// }
// char *d_str = strtok(data, ",");
// int d_int = atoi(strtok(NULL, ","));
// printf("Data string: %s\n", d_str);
// printf("Data Integer: %d\n", d_int);
// strcmp(data_str[i], d_str);
// data_int[i] = d_int;
// i++;
// }
i=0;
while (1)
{
printf("Enter a data point(-1 to stop input):");
scanf("\n%[^\n]s", data);
if (strcmp(data, "-1") == 0)
{
break;
}
int len = 0;
int cm = 0;
while (data[cm]!='\0')
{
if(data[cm]==',')
len++;
cm++;
}
char *d_str = strtok(data, ",");
char *token = strtok(NULL, ",");
int d_int = -999;
if(token!=NULL)
d_int = atoi(token);
if (len == 0)
printf("Error: No comma in string\n");
else if (len == 1)
{
if (d_int!=0)
{
printf("Data string: %s\n", d_str);
printf("Data Integer: %d\n", d_int);
strcpy(data_str[i], d_str);
data_int[i] = d_int;
i++;
}
else{
printf("Error: Comma not followed by an integer.\n");
}
}
else
{
printf("Error Too many commas in input.\n");
}
}
printf("%33s\n", title);
printf("%20s | %23s\n", col1, col2);
printf("-------------------------------------------------------------\n");
int j=0;
while(j<i){
printf("%20s | %23d\n", data_str[j], data_int[j]);
j++;
}
printf("\n\nHistogram:\n\n");
j=0;
while(j<i){
printf("%s ", data_str[j]);
int k=0;
while(k<data_int[j]){
printf("*");
k++;
}
printf("\n");
j++;
}
printf("\n");
return 0;
}
Please help modify my C program to be able to answer these questions, it seems the...
The program reads an unknown number of words – strings that all 20 characters or less in length. It simply counts the number of words read. The end of input is signaled when the user enters control-d (end-of-file). Your program prints the number of words that the user entered. ****** How do you I make it stop when control-d is entered. My code: #include <stdio.h> void main(void) { char sentence[100]; int i = 0; int count = 1; printf("Enter a...
Here is the (A3b-smallgrades.txt) text file: Here is the (A3b-largegrades.txt) text file: Here is the Program A3a without modification: #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char students[COLS][20]); void printGrades(int ROWS, int COLS, int grades[ROWS][COLS]); void getStudents(int COLS, char students[COLS][20]); void printStudents(int COLS, char students[COLS][20]); void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char Fgrades[]); void printFinalGrades(int COLS, char Fgrades[]); int main() { srand(time(0)); int stu = 0, assign = 0;...
5.10 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...
I need a basic program in C to modify my program with the following instructions: Create a program in C that will: Add an option 4 to your menu for "Play Bingo" -read in a bingo call (e,g, B6, I17, G57, G65) -checks to see if the bingo call read in is valid (i.e., G65 is not valid) -marks all the boards that have the bingo call -checks to see if there is a winner, for our purposes winning means...
Write helpful comments for the following code: use Vigenere cipher tech to encrypt and decrypt message The code: #include<stdio.h> #include <stdlib.h> char arr[26][26]; char message[22], key[22], emessage[22], retMessage[22]; int findRow(char); int findColumn(char); int findDecRow(char, int); int main() { int i = 0, j, k, r, c; k = 96; for (i = 0; i<26; i++) { k++; for (j = 0; j<26; j++) { arr[i][j] = k++; if (k == 123) k = 97; } } printf("\nEnter message\n"); fgets(message, 22,...
Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wunzip: file1 [file2 ...]\n"); return 1; } else{ for(int i =1; i< argc;i++){ int num=-1; int numout=-1; int c; int c1; FILE* file = fopen(argv[i],"rb"); if(file == NULL){ printf("Cannot Open File\n"); return 1; } else{ while(numout != 0){ numout = fread(&num, sizeof(int), 1, file); c...
In Programming language C - How would I convert my words char array into a string array so I can use the strcmp() function and alphabetically sort the words? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]){ int i =0; int j =0; int count =0; int length = strlen(argv[1]); for(i =0; i < length; i++){ if(isalpha(argv[1][i]) == 0 ||isdigit(argv[1][i] != 0)){ count ++; } printf("%c",argv[1][i]); } char *strings; int wordNum =0; int charNum =0; strings...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...
I'm having trouble getting my program to output this statement Enter a sentence: Test! There are 5 total characters. There are 1 vowel. There are 1 UPPERCASE letters. There are 3 lowercase letters. There are 1 other characters. Here's my code: #include<string.h> #include<stdio.h> #include<stdbool.h> int main() { char str[100]; int i; int vowels=0; int UC; int LC; int Others; int c; printf("Enter a sentence: \n"); gets(s); LC=countLC(&s); UC=countUC(&s); Others=countOthers(&s); printf("There are %d total characters.\n", ; for(i=0; i<strlen(str); i++){ if(isVowel(str[i])) vowels++;...
C++ HELP I need help with this program. I have done and compiled this program in a single file called bill.cpp. It works fine. I am using printf and scanf. Instead of printf and scanf use cin and cout to make the program run. after this please split this program in three files 1. bill.h = contains the class program with methods and variables eg of class file class bill { } 2. bill.cpp = contains the functions from class...