Re: im facing problem with fread()??
- From: manoj1978@xxxxxxxxx
- Date: 24 Aug 2005 03:30:51 -0700
Rajshekhar wrote:
> Hi ,
> i am writing a simple prgm to read a .txt file then store the contents
> into the array...
Please post the contents of triangle.txt.then someone can help you.
If triangle.txt is a binary file then try rb instead of r in fopen.
> 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: Villy Kruse
- Re: im facing problem with fread()??
- From: Rajshekhar
- Re: im facing problem with fread()??
- References:
- im facing problem with fread()??
- From: Rajshekhar
- im facing problem with fread()??
- Prev by Date: Re: im facing problem with fread()??
- Next by Date: Re: im facing problem with fread()??
- Previous by thread: Re: im facing problem with fread()??
- Next by thread: Re: im facing problem with fread()??
- Index(es):
Relevant Pages
|