hi, i am getting a segmentation fault in the following program.
when i am printf("%s", sixeof(helpText)) after the reallocation of space the answer is always 4. what does that mean? and why i am getting a segmentation fault? any help?Code:... FILE *fp; int helpSize=sizeof(char), i; char *helpText; char line[255]; char *filename="HELP"; GladeXML *xml; GtkWidget *mainTextbox; if ((fp = fopen(filename, "r")) == NULL) { fprintf(stdout, "Unable to open file <%s>\n", filename); exit(EXIT_FAILURE); } helpText = malloc(1); i = 1; while(fgets(line, sizeof(line), fp) != NULL) { printf("%d)", i++); //segmentation fault after the second append helpSize += strlen(line) * sizeof(char); realloc(helpText, helpSize); printf("%d\n", sizeof(helpText)); //size is always 4, what 4 though and why? strcat(helpText, line); } //here goes the statement to display the help //xml = glade_get_widget_tree(GTK_WIDGET(button)); //mainTextbox = glade_xml_get_widget (xml, "main_textbox"); //gtk_text_insert(main_textbox, help, -1, -1); //gtk_text_insert(GTK_ENTRY(mainTextbox), NULL, NULL, NULL, "HELP!!", -1); //gtk_entry_set_text(mainTextbox, "HELP!!"); free(helpText); fclose(fp);
thanks



LinkBack URL
About LinkBacks


