i am writing a program to count number of paragraphs
and it can successfully run
Code:
#include <stdio.h>
int main(int argc, char *argv[]) {
int para = 0;
char ch;
FILE *fp = fopen("InFile.txt", "r");
if(fp==NULL) {
printf("Cannot open file for reading!");
return 1;
}
while((ch=fgetc(fp))!=EOF) {
if(ch=='\n')
para++;
}
fclose(fp);
printf("number of paragraphs is : %d\n", para+1);
getchar();
return 0;
}
however, i would like to make it into a function...
then i change it to::
Code:
#include <stdio.h>
void total_paragraph(FILE*infile)
{
int main(int argc, char *argv[]) {
int para = 0;
char ch;
FILE *fp = fopen("InFile.txt", "r");
if(fp==NULL) {
printf("Cannot open file for reading!");
return 1;
}
while((ch=fgetc(fp))!=EOF) {
if(ch=='\n')
para++;
}
fclose(fp);
printf("number of paragraphs is : %d\n", para+1);
getchar();
return 0;
}
}
then it shows something below [pink circle]...
what happen?
thank you very much