I have a seg fault in this function and i can't seem to pin it down. Appreciate any help you guys could give.Thanks.
Code:int AllocateFile(FILE *filename,long num_of_records){ /*iterates through file contents and adds each character to the appropiate field*/ int ndx=0; int field=0;/*ndx for field ndx next for temp counter and field for what field number we in*/ size_t word_length=0; int character; int comma_count=0; char buffer[BUFSIZ];/*really holding integers should put it to char*/ RECORD person[num_of_records];/*array of records named person to hold each line in file*/ /*go through file and puts contents in the array*/ while ( (character=fgetc(filename)) !=EOF){ buffer[ndx++]=character; if ( (buffer[ndx] =='\n') ) field+=1;/*if its a newline then its a new field*/ if ( (buffer[ndx] == ',') ){ comma_count+=1;/*update comma count so know where we are in file*/ switch(comma_count){ case 1: buffer[ndx-1]='\0';/*terminate and make buffer a string*/ strcpy(person[field].field1,buffer); buffer[ndx]= buffer[ndx-word_length];/*buffer ndx goes to zero*/ puts(person[field].field1); break; case 2: buffer[ndx-1]='\0'; break; }//end of break } }}



LinkBack URL
About LinkBacks


