ok jeg har lavet lidt om på den. den virker hvis der ikke er duble space. ved ikke hvordan jeg skal løse dette
#include <stdio.h>
FILE *Rfile;
char text[4000];
char textFile[100];
int line()
{
int lineCount=1;
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;
}
}fclose(Rfile);
printf("File contains %d lines.\n", lineCount);
}
int words()
{
FILE * Rfile;
char text;
int words = 0;
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
{
do {
text = fgetc (Rfile);
if(text == ' ' || text == ',' || text == '.' || text == ':' || text == '?'
|| text == ';' || text == '!') /* see if there is 2 or more seperators right after another
if this is it will only count as 1 word*/
words++;
if (text = ' ');
words--;
} while (text != EOF);
fclose (Rfile);
printf ("File contains %d words.\n",words);
}
return 0;
}int main()
{
line();
words();
}