This is a simple piece of code, but when I try to debug it in GDB I ran into problems; Here are my command line inputs:
gdb test
b main
info locals
the source code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char *str = "1111 1111\n";
size_t n =2;
FILE *outptr = fopen("target.txt","w");
fwrite(str,strlen(str),1, outptr);
char *str2 = "22222\n";
fwrite(str2,strlen(str2),1, outptr);
char *str3 = "3333\n";
fwrite(str3,strlen(str3),1, outptr);
char *str4 = "4444\n";
fwrite(str4,strlen(str4),1, outptr);
// char *str2 = "2222\n";
// fwrite(str2,strlen(str2),3, outptr);
fclose(outptr);
return 1;
}
at the breakpoint of main, gdb shows all local variables already defined, but i have not step into the declarations yet. What troubles me more was that it seems the variables had non-null values coming from nowhere.
Thanks