Hello all,
I'm a new member in this website, hope I can help and be helped in this wonderful place.
My name is Maroun, a computer engineering student. My age is 25.
Now to the question.
I have this struct:
Code:
typedef struct cell {
char _name[3];
int _calcResult;
int _depend[MAX_CELLS];
} Cell;
and this is my main:
Code:
int main(int argc, char* argv[]) {
FILE *fp;
int i;
fp=fopen(argv[1], "r");
Cell Cells[MAX_CELLS];
fillNames(fp,Cells);
for(i=0;i<4;i++)
printf("%s\n", Cells[i]._name);
}
Code:
static void fillNames(FILE* fp, Cell *Cells) {
char line[3];
int i=0;
while(fgets(line, sizeof line, fp)!=NULL) {
strcpy(Cells[i]._name, line);
i++;
}
}
I have an array of structs and I'm trying to insert the first two chars from each line from the file into the _name field in the struct inside the array.
I get this message:
Segmentation fault.
(I checked the file, and checked the parameters.. I just didn't wrote it here)