visual studio 2010 - not able to read a text file in vs2010 using c .. i am new to vs please help me -
i kept text file @ same place .exe existing , not working .. hi code , kept text file @ same place .exe existing , not working .. hi code , kept text file @ same place .exe existing , not working ..
int main(int argc, _tchar* argv[]) { int result = 0; char ca, file_name[25]; file *fp; //printf("enter name of file wish see\n"); gets(file_name); fp = fopen("sample.txt","r"); // read mode if( fp == null ) { perror("error while opening file.\n"); //exit(exit_failure); } if( fgets (str, 60, fp)!=null ) { /* writing content stdout */ puts(str); } fclose(fp); }
try , work in c & c++ , use code perform file operation
int main() { char filename[10];char extension[5]=".txt"; printf("enter name of file wish see\n"); gets(filename); fflush(stdin); filename[10]='\0'; strcat(filename,extension); puts(filename); file *p; char acline[80]; p=fopen(filename,"r"); if(p==null) { printf("%s file missing\n",filename);system("pause"); } fseek(p,0,seek_set); // setting file pointer beginning of file while (!feof(p)) // detecting end of file { fgets(acline,80,p); puts(acline); } printf("\n file end\n"); system("pause"); }
*but while(!feof())
has issues see this
Comments
Post a Comment