So that problem is sorted out, I seem to have run into another problem
I am trying to read the data from a file using fread but I keep getting 0 bytes read although there is data in my file.
Code:
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *fp;
float a,b;
char buffer[100],c;
int i,bytesread;
if ((fp=fopen("E:\\test.txt", "rb")) == NULL)
{
printf("Unable to open the file\n");
exit(1);
}
a = fseek(fp,0,SEEK_END);
printf("The value of a is:%d\n",a);
b = ftell(fp);
printf("The value of b is:%f\n",b);
bytesread = fread(buffer,sizeof(char),10,fp);
printf("The total number of bytes read =%d\n",bytesread);
}
This is what I get as output
The value of a is:0
The value of b is:5.000000
The total number of bytes read =0
I tried using the getc function and writing it into a buffer, that seems to work fine but for some reason fread is not working, anyone have any idea as to what is wrong with my prog.
Thanks