I was writing a program to read text in a file and store the words.
MY inputTextFile was aw.txt
Code:
first line of file
this is last
my program to read the file
Code:
#include <stdio.h>
int main(void){
FILE *fp;
char readInLine[200];
int i=0;
fp=fopen("aw.txt","r"); //open file
while(fgets(readInLine,200,fp)!=NULL) { //read each line of file
i=0;printf("\n\nCurrent Line:%s",readInLine);
printf("\n------------");
while(readInLine[i]!='\0'){ //run till end of line
if(readInLine[i]==' '){ //if space found
printf("\nfound a space");
}
else if(readInLine[i]=='\n'){ //if end of line found
printf("\nfound a end Line");
}
else{
}
i++;
}
}
}
The program worked fine for the first line.found 3 spaces,the found end of the line.
for the second line it found 2 spaces. MY QUESTION WAS HOW DO I DETECT END OF LINE HAS BEEN DETECTED FOR THE LAST LINE ?
I was not able to store the word "last".How do i do that? readInLine[i]=="WHAT " ???
Hope you guys understand my problem and can help me out.thanx