D
danu
I'm trying to read data from a file (line by line) and trying to assign
the values to the structure members. I'm kind of lost in this case
since the books I'm using for reference doesn't give any examples about
this case.
typedef struct{
char magicNum[2];
int width;
int height;
int maxGrey;
int pixels[ROW][COLUMN];
} image
and the file i'm trying to read is looks like this. (it's a .pgm image)
P2
24 7 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15
My question is : If I read the input line by line, how do I assign
values to structure members?
I was trying to use some approach like:
while(fgets(buffer, MAX, infile)!=NULL){
strcpy(image.magicNum, getWord(buffer, MAX);
image.width= getWord(buffer, MAX);
....
.....
}
(getWord is a function that I used to get word by word
from the buffer after I executed the fgets function)
I would highly appreciate any help. I don't need the exact source code.
I just need any idea about this procedure.
thanks.
the values to the structure members. I'm kind of lost in this case
since the books I'm using for reference doesn't give any examples about
this case.
typedef struct{
char magicNum[2];
int width;
int height;
int maxGrey;
int pixels[ROW][COLUMN];
} image
and the file i'm trying to read is looks like this. (it's a .pgm image)
P2
24 7 15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15
My question is : If I read the input line by line, how do I assign
values to structure members?
I was trying to use some approach like:
while(fgets(buffer, MAX, infile)!=NULL){
strcpy(image.magicNum, getWord(buffer, MAX);
image.width= getWord(buffer, MAX);
....
.....
}
(getWord is a function that I used to get word by word
from the buffer after I executed the fgets function)
I would highly appreciate any help. I don't need the exact source code.
I just need any idea about this procedure.
thanks.