I do not write in C often and am having some trouble. For starters I think I am sure I am putting lines I am reading in from textfiles into a 2D array correctly. Also I am having a problem when I try and put the line into the array. I get a warning that the assignment makes integer from pointer without a cast. I want it to be a char and I think thats why I am getting a Seg Fault since it is bigger than the size i allocated. I have included my code below. I bet this is a stupid mistake, I havent used C in a while thanks!
#include <stdio.h>
FILE *fid;
char line[70];
char dna[66800][70];
main() {
int counter = 0;
fid = fopen("dna.fna","r");
while(fgets(line, sizeof(line), fid) != NULL){
//fputs ( line, stdout );
dna[counter][0] = line; //Getting a Seg Fault here
counter++;
}
fclose(fid);
}
The assignment in this case should actually be a copy, like this:
The warning you are getting is caused by
linebeing decayed into a pointer and trying to assign that to achar.You also have to be sure that
counterwill never exceed 66800.