Question
#include #include #include void copy(FILE * fpin, FILE * fpout) { //function to copy char ch; fscanf(fpin, %c, & ch); //read a char from infile
#include
#include
#include
void copy(FILE * fpin, FILE * fpout) { //function to copy
char ch;
fscanf(fpin, "%c", & ch); //read a char from infile
while (!feof(fpin)) { //loop until end of file
if (ch >= 'a' && ch
ch -= 32; //convert it to upper case. ASCII value difference
}
fprintf(fpout, "%c", ch); //print character to outfile
fscanf(fpin, "%c", & ch); //read next character from infile
}
}
void sort(FILE * fpin, FILE * fpout) { //function to sort lines
char lines[50][11];
char line[10];
int i = 0, j = 0, tlines = 0;
char ch;
fscanf(fpin, "%c", & ch); //read a character from infile
while (!feof(fpin)) { //loop until eof
if (ch == ' ') { /ew line character
lines[i][j] = '\0'; //end current line
i++; //start new line
j = 0;
} else { /ot a new line char
if (j
lines[i][j] = ch; //copy character
j++; //increment char count
}
}
fscanf(fpin, "%c", & ch); //read next char
}
lines[i][j] = '\0'; //end end current line
tlines = i + 1;
//sort all lines using selection sort technique
for (i = 0; i
for (j = i + 1; j
if (strcmp(lines[i], lines[j]) > 0) {
strcpy(line, lines[i]);
strcpy(lines[i], lines[j]);
strcpy(lines[j], line);
}
}
}
//print sorted lines to output file
for (i = 0; i
fprintf(fpout, "%s ", lines[i]);
}
}
void wc(FILE * fpin, FILE * fpout) { //function to count words and lines
int wc = 0, lc = 0; //initialize word and line counts to 0
char ch;
fscanf(fpin, "%c", & ch); //read a char from infile
while (!feof(fpin)) { //loop until eof
if (ch == ' ') { /ew line character
lc++; //increment line count
wc++; //increment word count
} else if (ch == ' ') { //space character
wc++; //increment word count
}
fscanf(fpin, "%c", & ch); //read next char
}
wc++;
lc++;
//print word and line count to console
printf("Number of words: %d ", wc);
printf("Number of lines: %d ", lc);
//print word and line count to out file
fprintf(fpout, "Number of words: %d ", wc);
fprintf(fpout, "Number of lines: %d ", lc);
}
int main(int argc, char * argv[]) { //amin method
if (argc != 4) { //less than 3 command line arguments
//print usage instructions
printf("Usage: \tThis program must be provided with three arguments through command line. "
"\tchoice infile outfile \tchoice - is the choice of operation "
"\tinfile - this is the input file name "
"\toutfile - this is the output file name ");
return 0;
}
int choice = atoi(argv[1]); //convert choice to int
FILE * fpin = fopen(argv[2], "r"); //open input file
if (fpin == NULL) { //input file open failure
//print error message and return
printf("Error! No such file - infile ");
return 0;
}
FILE * fpout = fopen(argv[3], "w"); //open output file
if (fpout == NULL) { //output file open failure
//print error message and return
printf("Error! Cannot save file - outfile ");
return 0;
}
switch (choice) { //switch input choice
case 1: //first choice
//call copy function to copy texts from input file to output
copy(fpin, fpout);
break;
case 2: //second choice
//call function to sort the lines of input file and
//copy 10 characters from each lines to output file
sort(fpin, fpout);
break;
case 3: //third choice
//call function to count words and lines of input file
//and print result to output file
wc(fpin, fpout);
break;
default: //invalid choice
//print error message and return
printf("Wrong choice, the only available values are 1, 2, 3 ");
return 0;
}
return 0;
}
Can I get help understanding why this program isnt working?
ON ner nacta input - Notepad File Edit Format View Help Community College of the Air Force Alabama A & M University University of Alabama at Birmingham Amridge University University of Alabama in Huntsville Alabama State University The University of Alabama st Central Alabama Community College Athens State University Auburn University-Montgomery Auburn University Main Campus Birmingham Southern College Chattahoochee Valley Community College Concordia College Alabama South University-Montgomery output - Notepad File Edit Format View Help line 5: syntax error near unexpected token ( line 5: "void copy (FILE * fpin, FILE * fpout) { //function to copyStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started