Another part of the task is, that the User could define how many lines should be analyzed. So I tried to program the first steps for it. But there is the following problem: Anyway it analyzes the whole file, because the while-command from you does this in one step. So what should/could I change?
Maybe I have to insert a line like this(?):
Code:
ret=fgets(Zeile,100,datei);
Code:
#include <stdio.h>
struct list{
char word[26];
int count;
};
int main(void)
{
FILE * fp;
int i, CountOfLines, x=1;
char line[101], *ret;
struct Liste entry[600];
if((fp=fopen("Demodatei.txt","r+")) == NULL)
{
printf("ERROR: ...\n");
}
else
{
printf("\nHow many lines should be analyzed?\n");
scanf("%d",&CountOfLines);
if (CountOfLines== 0) printf("The whole file will be analyzed"); // this will be edited later...
else
{
CountOfLines++;
i = 1;
while(x<CountOfLines)
{
while((fscanf(fp, "%s", entry[i].word)) > 0 )
{
printf("%2d. word: %s\n",i,entry[i].word);
i++;
x++;
}
}
}
printf("\ntotal count: %d",i-1);
fclose(fp);
printf("\n");
}
fflush(stdin);
getchar();
return 0;
}