Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C
#include <stdio.h>

int main()
{
        FILE *ff;
        ff = (fopen("E:\\empSal.txt","r"));
        fprintf(ff,"Emp: %s \t sal: %d $ \n",name,sal);
        fclose(ff);
        return 0;
}


What I have tried:

i added write mode it done but when i tried read it didn't ...
Posted
Updated 31-Aug-17 19:05pm
Comments
Mohibur Rashid 31-Aug-17 23:19pm    
Show your read code that didnt read

Make use of fread / fgets using your file pointer of your file.

A sample of fgets is as below.


FILE *fp_r = NULL;
	char buff[2049] = {""};
	
	fp_r = fopen(file_path, "r");
	if(fp_r)
	{
		while(!feof(fp_r))
		{
			memset(buff,0,sizeof(lv_buff));
			fgets(buff,2048,fp_r); // Read your file data
			
			// do something with your buffer read
			....
			...
			..
			.
		}
		
		fclose(fp_r);
	}
	else
	{
		// return file open error
	}
 
Share this answer
 
You are trying to write to the file (while you have open it for reading).
Use fread (or fscanf) for reading, see fread[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900