Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need some help with C programing. I can\'t really seem to figure out this inpuit

ID: 3814823 • Letter: N

Question

Need some help with C programing.

I can't really seem to figure out this inpuit errror that i am running into as i am not sure where i should put the data string and data input output part.

Here is the error

Here is my code for this assignment.

#include <stdio.h>
#include <string.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: ");
fgets (title, 50, stdin);
printf("You entered: %s ", title);

printf("Enter the column 1 header: ");
fgets (col1, 50, stdin);
printf("You entered: %s ", col1);

printf("Enter the column 2 header: ");
fgets (col2, 50, stdin);
printf("You entered: %s ", col2);

int count = 0;
char dataPoint[50];
while (count < 50) {
printf("Enter a data point(-1 to stop input): ");
fgets (dataPoint, 50, stdin);
if (atoi(dataPoint) == -1) {
break;
}
int commas = 0;
int i = 0;
int intFound = 0;
char integerValue[5] = "";
int commaAfterInt = 0;
  
while (dataPoint[i] != '') {

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] != ''; j++);
integerValue[j] = dataPoint[i];
integerValue[j + 1] = '';
}
i++;
}
if (commas == 0) {
printf("Error: No comma in string. ");
} else if (commas > 1) {
printf("Too many commas in input. ");
} else if (commaAfterInt == 1) {
printf("Comma not followed by an integer ");
} else {
point[count++] = atoi(integerValue);
}
}
printf(" FORMATTED TABLE ");
printf("%33s ", title);
printf("%23s", col1);
printf(" | %20s ----------------------------------------------------- ", col2);

int i = 0;
// printf("Count:%d ",count);
while (i < count) {
printf("%23s | %20d ", names[i], point[i]);
i++;
}

printf(" FORMATTED HISTOGRAM ");
i = 0;
while (i < count) {
printf(" %28s", names[i]);
int j = 0;
while (j < point[i]) {
printf("*");
j++;
}
printf(" ");
i++;
}
return 0;
}

Here is the the whole assignment details.

(1) Prompt the user for a title for data. Output the title. (1 pt)

Ex:


(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)

Ex:


(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 have finished entering data points. Output the data points. Store the string components of the data points in an array of strings. Store the integer components of the data points in an array of integers. (4 pts)

Ex:


(4) Perform error checking for the data point entries. If any of the following errors occurs, output the appropriate error message and prompt again for a valid data point.

If entry has no comma

Output: Error: No comma in string. (1 pt)

If entry has more than one comma

Output: Error: Too many commas in input. (1 pt)

If entry after the comma is not an integer

Output: Error: Comma not followed by an integer. (2 pts)


Ex:


(5) Output the information in a formatted table. The title is right justified with a width of 33. Column 1 has a width of 20. Column 2 has a width of 23. (3 pts)

Ex:


(6) Output the information as a formatted histogram. Each name is right justified with a width of 20. (4 pts)

Ex:

3. Compare output Number of Novels Authored Author name Input Number of novels Jane Austen, 6 Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header: You entered: Author name Your output starts with Enter the column 2 header: You entered: Number of novels Enter a data point. (-1 to stop input): Enter a data point (-1 to stop input) FORMATTED TABLE Number o Enter a title for the data: You entered: Number of Novels Authored Enter the column 1 header: You entered: Author name Expected output starts with Enter the column 2 header: You entered: Number of novels Enter a data point. (-1 to stop input) Data string Jane Austen Data integer 6 0/4

Explanation / Answer

PROGRAM CODE:

#include <stdio.h>
#include <string.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: ");
fgets (title, 50, stdin);
printf("You entered: %s ", title);
printf("Enter the column 1 header: ");
fgets (col1, 50, stdin);
printf("You entered: %s ", col1);
printf("Enter the column 2 header: ");
fgets (col2, 50, stdin);
printf("You entered: %s", col2);
int count = 0;
char dataPoint[50];
while (count < 50) {
printf(" Enter a data point(-1 to stop input): ");
fgets (dataPoint, 50, stdin);
if (atoi(dataPoint) == -1) {
break;
}
int commas = 0;
int i = 0;
int intFound = 0;
char integerValue[5] = "";
int commaAfterInt = 0;
  
while (dataPoint[i] != '') {
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] != ''; j++);
integerValue[j] = dataPoint[i];
integerValue[j + 1] = '';
}
i++;
}
if (commas == 0) {
printf("Error: No comma in string. ");
} else if (commas > 1) {
printf("Too many commas in input. ");
} else if (commaAfterInt == 1) {
printf("Comma not followed by an integer ");
} else {
point[count++] = atoi(integerValue);
} //These lines were missing
printf(" Data string: %s", names[count-1]);
printf(" Data integer: %d", point[count-1]);
}
printf(" FORMATTED TABLE ");
printf("%33s", title);
printf(" ");
printf("%20s | %23s ", col1, col2);
printf("----------------------------------------------------- ");
int i = 0;
// printf("Count:%d ",count);
while (i < count) {
printf("%20s | %23d ", names[i], point[i]);
i++;
}
printf(" FORMATTED HISTOGRAM ");
i = 0;
while (i < count) {
printf(" %28s", names[i]);
int j = 0;
while (j < point[i]) {
printf("*");
j++;
}
printf(" ");
i++;
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote