Thread: Help debugging this

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    For example:
    Code:
    # include <stdio.h>
    # include <conio.h>
    # include <string.h>
    
    struct RecordInfo {
    	char Student_Name[25];
    	int  id_num[10];
    	int  Tel_Num[7];	// no "." in variable names!
    	char Address[40];
    	char Program[15];
    };
    
    int main () {
    	struct RecordInfo test;
    
    	return 0;
    }
    You can compile and run this code. It does not do anything, of course, but at least you now know it has no syntax errors. (You may get a warning for an "unused" variable).

    Vis, a date of birth is almost certainly a string, so fgets() is good:
    Code:
    char buffer[1024];
    printf("Enter date of birth: ");
    fgets(buffer,1024,stdin);
    fprintf(stderr, "->%s<-",buffer);
    There's four lines you can add and test. The fprintf line is just for debugging. You can //comment them out. fprintf(stderr...) ensures it will be output immediately (printf is buffered) which is better for debugging.

    You'll notice:
    ->dateofbirth
    <-
    because the input has a newline in it. If that's a problem, your next little task is how to get rid of the newline.
    Last edited by MK27; 04-25-2010 at 05:21 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help on debugging
    By Masterx in forum C++ Programming
    Replies: 56
    Last Post: 01-30-2009, 10:09 AM
  2. Dev-C++: Problems with Breakpoint Debugging
    By Thileepan_Bala in forum C Programming
    Replies: 1
    Last Post: 01-17-2008, 10:48 AM
  3. Debugging Dev C++
    By tuurb046 in forum Tech Board
    Replies: 10
    Last Post: 08-16-2007, 12:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 07:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 08:56 AM