Question: #include #include #include #include #include #define MAXSTRING 200 // check if a character c is a digit bool isDigit(char c) { if ('0'
|
#include | |
| #include | |
| #include | |
| #include | |
| #include | |
| #define MAXSTRING 200 | |
| // check if a character c is a digit | |
| bool isDigit(char c) { | |
| if ('0' <= c && c <= '9') { | |
| return true; | |
| } else { | |
| return false; | |
| } | |
| } | |
| // append character c to string s | |
| void appendChar(char* s, char c) { | |
| char charToStr[2]; // convert char to string | |
| charToStr[0] = c; | |
| charToStr[1] = '\0'; // put NUL to terminate string of one character | |
| strcat(s, charToStr); | |
| } | |
| int main () { | |
| char inputLine[MAXSTRING]; // temporary string to hold input line | |
| char cityStr[MAXSTRING]; // city name | |
| int lineNum; // line number (city rank) | |
| int popInt; // population | |
| char temp[MAXSTRING]; // temp string to build up extracted strings from input characters | |
| FILE* fp; | |
| fp = fopen("pop.csv","r"); | |
| if (fp != NULL) { | |
| fgets(inputLine, MAXSTRING, fp); // prime the pump for the first line | |
| while (feof(fp) == 0){ | |
| // ********* YOUR CODE GOES HERE!!!!!!!!! | |
| // process the line - print out raw line and the parsed fields | |
| printf("> %.50s ", inputLine); | |
| printf("[%s]: %d ", cityStr, popInt); | |
| // get next line | |
| fgets(inputLine, MAXSTRING, fp); | |
| } | |
| fclose(fp); | |
| } else { | |
| printf("File not found! "); | |
| } | |
| return 0; | |
| } |
Convert each city name to a string with no double quotes and convert each population to an integer (no commas!). For each line, you will print out (a) the first 50 characters of the input line, (b) the city name, and (c) the population.
assume the lines in the cv file look like this
"New york", "100,068,898"
"California", "23,335,632" etc...
Please use C program and insert the code in the appropriate field above.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
