I want to write code were the user is asked to write the name of a file. Then I want to analyze the file's content for a symbol, let's say 'e'.
My problem is that I don't know how to start analyzing the file the correct way so that the content can be checked.
int main() {
char c[1000], file_name[1000];
int i;
int s = 0;
FILE *fp;
printf("Enter the name of file you wish to see\n");
gets(file_name);
if ((fp = fopen(file_name, "r")) == NULL){
printf("Error! opening file");
exit(1);
}
if (fp) {
while (fscanf(fp, "%s", c) != EOF) {
printf("%s", c);
}
fclose(fp);
for (i = 0; c[i] != '\0'; ++i) {
puts(c);
if (c[i] == 'e') {
++s;
}
}
printf("\nWhite spaces: %d", s);
_getche();
return 0;
}
}
strcat(myFullString, c);this will append the new content to the "myFullString" array and you will then be able to use is in your for loop Look at this example: programmingsimplified.com/c-program-concatenate-stringsfread()? cplusplus.com/reference/cstdio/fread Tryfread(c,sizeof(char),1000,fp);Remember that in this case,cis an array of char, not a string. If you wantcto remain a string :fread(c,sizeof(char),999,fp);c[999]='\0';