im facing problem with fread()??
- From: "Rajshekhar" <rajshekhar3@xxxxxxxxx>
- Date: 24 Aug 2005 02:29:14 -0700
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("triangle.txt","r");
if(fp1 == NULL)
{
printf("file cant be opend");
exit(0);
}
num=fread(buf,sizeof(int),5,fp1);
printf("num of elements read =%d\n",num);
for(i=0;i<5;i++)
printf("%d\n",buf[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
.
- Follow-Ups:
- Re: im facing problem with fread()??
- From: Peter "Shaggy" Haywood
- Re: im facing problem with fread()??
- From: Christopher Benson-Manica
- Re: im facing problem with fread()??
- From: Nick Keighley
- Re: im facing problem with fread()??
- From: manoj1978
- Re: im facing problem with fread()??
- From: Kuku
- Re: im facing problem with fread()??
- Prev by Date: Re: Why can't the parameter be const in this program?
- Next by Date: Re: im facing problem with fread()??
- Previous by thread: Why can't the parameter be const in this program?
- Next by thread: Re: im facing problem with fread()??
- Index(es):
Relevant Pages
|