kan godt nok ikke få den wordcounter til at virke nogen der kan give lidt hjælp
#include <stdio.h>
FILE *Rfile;
char text[4000];
int line()
{
int lineCount=1;
char textFile[100];
printf("plz give me the name of the file \n");
scanf("%s", &textFile);
Rfile = fopen(textFile, "r");
if(Rfile==NULL) {
printf("Error: can't open %s.\n", textFile);
/*if the program cant finde the file */
return 1;
}
else {
printf("i will now open the file.:\n\n");
while (!feof(Rfile)) {
fgets(text, 4000, Rfile);
lineCount++;
break;
}
}
printf("File contains %d lines.\n", lineCount);
}
int words()
{
int word =1;
char text2;
if (Rfile==NULL)
perror ("Error reading file");
else
{
do {
text2 = fgetc (Rfile);
if (text2 == ' ')
word++;
} while (text2 != EOF);
}
printf("number of words of words %d\n", word);
}
int main()
{
line();
words();
fclose(Rfile);
}
Indlæg senest redigeret d. 26.10.2008 11:47 af Bruger #5409