Hi ,
i am writing a simple prgm to read a .txt file then store the contents
into the array...
program as follows:
--------------------------
#include<stdio. h>
int main()
{
FILE *fp1;
int buf[5];
int num,i;
fp1=fopen("tria ngle.txt","r");
if(fp1 == NULL)
{
printf("file cant be opend");
exit(0);
}
num=fread(buf,s izeof(int),5,fp 1);
printf("num of elements read =%d\n",num);
for(i=0;i<5;i++ )
printf("%d\n",b uf[i]);
return 0;
}
------------------
i am getting no.of elements read as 0,but file is openable...
the elements as junk numbers...
can anybody tell me wat is the problem in doing this ..????
is it that i m using fread wrongly or it behaves abnoramlly???
TIA
Regards,
Rajshekhar
i am writing a simple prgm to read a .txt file then store the contents
into the array...
program as follows:
--------------------------
#include<stdio. h>
int main()
{
FILE *fp1;
int buf[5];
int num,i;
fp1=fopen("tria ngle.txt","r");
if(fp1 == NULL)
{
printf("file cant be opend");
exit(0);
}
num=fread(buf,s izeof(int),5,fp 1);
printf("num of elements read =%d\n",num);
for(i=0;i<5;i++ )
printf("%d\n",b uf[i]);
return 0;
}
------------------
i am getting no.of elements read as 0,but file is openable...
the elements as junk numbers...
can anybody tell me wat is the problem in doing this ..????
is it that i m using fread wrongly or it behaves abnoramlly???
TIA
Regards,
Rajshekhar
Comment