i am working in c language and i have to debug my code as i want to see the behavior of my program.
i tried these command in my linux terminal:
gcc readFile.c
gdb a.out
b main
run
next
below is my code file
void main()
{
struct voter v[10];
FILE* fin;
fin=fopen("voters.txt","r");
if(fin == NULL) {
perror("Error opening file");
return(-1);
}
char buffer[2000];
char arr[10][100];
int i=0;
while(fgets(buffer,2000,fin)!=NULL)
strcpy(arr[i++],buffer);
fclose(fin);
char del[2]="/";
char * token;
token=strtok(arr[0],del);
i=0;
while(1)
{
strcpy(v[i].name,token);
token = strtok(NULL, del);
strcpy(v[i].id,token);
printf("%s\t%s\n",v[i].name,v[i].id);
token=strtok(arr[i+1],del);
if(token==NULL)
break;
}
}
after trying the above commands the programs runs completey to end to the file. what i was expecting that it should run next line just after main(). I don't have any idea what to do to debug my program. Also it is not any break point on any line like this
break 22
but to no avail. so i'm struck in it that how to debug my code