0

hi i have a 3 part question. can any one explain how can i read from a file and store it in array.(have to use fread).
the way i was thinking of doing this was.

int ar[50]; 
int ar2[50];
//read 20 charater at a time
while(fread(ar, 1, 20, file) != NULL)
{
        ar2[i] = ar;
}

partb:
how read one word at a time, by using fread.

while(fread(ar, SIZE, file) != 0) 
     {
     }

part3:
how read one line at a time, by using fread. i think its

while(fread(ar, SIZE, file) != 0) 
     {
     }

Edited by pyTony: fixed formatting

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

while(fread(ar, 1, 20, file) != NULL)
That only reads 20 bytes of data instead of 20 * sizeof(int) number of bytes. You need this?

while(fread(ar, 20, sizeof(int), file) != NULL)

how read one line at a time,
You mean how to read one integer at a time?

int i = 0;
while( fread( &ar[i], 1, sizeof(int), file) != NULL)
   ++i;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.