Help debugging this

This is a discussion on Help debugging this within the C Programming forums, part of the General Programming Boards category; Code: can somebody help debug a program i have so far please these are errors : ------ Build started: Project: ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    26

    Help debugging this

    Code:
    can somebody help debug a program i have so far please these are errors :
    
    ------ Build started: Project: student, Configuration: Debug Win32 ------
    Compiling...
    student.cpp
    e:\student.cpp(9) : error C2143: syntax error : missing ';' before '.'
    e:\student.cpp(9) : error C2238: unexpected token(s) preceding ';'
    e:\student.cpp(13) : error C2143: syntax error : missing ';' before '}'
    e:\student.cpp(18) : error C2556: 'void main(void)' : overloaded function differs only by return type from 'int main(void)'
            e:\student.cpp(5) : see declaration of 'main'
    e:\student.cpp(18) : error C2371: 'main' : redefinition; different basic types
            e:\student.cpp(5) : see declaration of 'main'
    e:\student.cpp(20) : error C2146: syntax error : missing ';' before identifier 'Student_Name'
    e:\student.cpp(20) : warning C4551: function call missing argument list
    e:\student.cpp(20) : error C2065: 'Student_Name' : undeclared identifier
    e:\student.cpp(21) : error C2065: 'Student_Name' : undeclared identifier
    e:\student.cpp(27) : error C2065: 'Student_Name' : undeclared identifier
    e:\student.cpp(27) : error C2228: left of '.s' must have class/struct/union
            type is ''unknown-type''
    e:\student.cpp(27) : error C2448: 'RecordInfo' : function-style initializer appears to be a function definition
    e:\student.cpp(41) : error C2059: syntax error : '}'
    e:\student.cpp(41) : error C2143: syntax error : missing ';' before '}'
    e:\student.cpp(41) : error C2059: syntax error : '}'
    e:\student.cpp(45) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    e:\student.cpp(45) : error C2365: 'printf' : redefinition; previous definition was 'function'
            c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(287) : see declaration of 'printf'
    e:\student.cpp(45) : error C2440: 'initializing' : cannot convert from 'const char [46]' to 'int'
            There is no context in which this conversion is possible
    e:\student.cpp(46) : error C2065: 'name' : undeclared identifier
    e:\student.cpp(46) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    e:\student.cpp(46) : error C2365: 'scanf' : redefinition; previous definition was 'function'
            c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(306) : see declaration of 'scanf'
    e:\student.cpp(46) : error C2078: too many initializers
    e:\student.cpp(47) : error C2059: syntax error : 'for'
    e:\student.cpp(47) : error C2143: syntax error : missing ')' before ';'
    e:\student.cpp(47) : error C2143: syntax error : missing ';' before '<'
    e:\student.cpp(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    e:\student.cpp(47) : error C2143: syntax error : missing ';' before '++'
    e:\student.cpp(47) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    e:\student.cpp(47) : error C2086: 'int i' : redefinition
            e:\student.cpp(47) : see declaration of 'i'
    e:\student.cpp(47) : error C2059: syntax error : ')'
    e:\student.cpp(48) : error C2447: '{' : missing function header (old-style formal list?)
    e:\student.cpp(98) : error C2059: syntax error : '}'
    e:\student.cpp(98) : error C2143: syntax error : missing ';' before '}'
    e:\student.cpp(98) : error C2059: syntax error : '}'
    Build log was saved at "file://e:\Debug\BuildLog.htm"
    student - 33 error(s), 1 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    .cpp means C++, so you should be in that forum.

    Start at the top, and work your way down. You're missing a couple semicolons, you've screwed up the definition of main, and so on. Some errors may "fix themselves" -- once you have a valid declaration of Student_Name, for instance, you're probably going to lose several errors.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    Code:
    # include <stdio.h>
    # include <conio.h>
    # include <string.h>
    
        int main ();
    
    	struct RecordInfo{char Student_Name[25];
    					  int  id_num[10];
    					  int  Tel.Num[7];
    					  char Address[40];
    					  char Program[15];
    	};
    	struct DOB{int dd,mm,yyyy};
    	// Function Prototype
    
    		void RecordInfo(RecordInfo);
    
    		void main (void) {
    
    			RecordInfo Student_Name;
    			RecordInfo (Student_Name);
    
    			getch();
    
    		}
    
    		void RecordInfo(Student_Name.s){
    
    			printf("Enter name & id_num");
    			scanf("%d, %s"&s.name,s.id_num);
    
    			printf("Enter student's address");
    			scanf ("%c",& s.address);
    
    			printf("Enter student's D.O.B & Tel.Num");
    			scanf("%d %d",& s. D.O.B, s.Tel.Num);
    
    			printf("Enter student Program_Name");
    			scanf("%s",& s.Program);
    		}
    	};
    
    		int Update_Records;
      char Update[50];
      printf("Enter Name of the person you wish to change: ");
      scanf("%s", &name);
        for (int i=0;i<10;i++);
        {
            if (strcmp(name[i].FirstName) == 0);
            {
             printf("What do you want to Modify?\n");
             printf("Press 1. to edit Last Name\n Press 2. to edit First Name\n Press 3. to edit Id Num\n Press 4. to edit D.O.B\n Press 5. to edit Address\n Press to edit Telephone number\n Press 7. to edit Program Name\n");
             scanf("%d", &Update_Records);
             switch (Update) {
                 case 1:
                  printf("Enter the new Last Name: ");
                  scanf("%d", &students[i].Last Name);
                  break;
    
                case 2:
                 printf("Enter student's updated First Name: ");
                 scanf("%s", &RecordInfo[i].First Name);
                 break;
    
                case 3:
                 printf("Enter student's updated Id Num  : ");
                 scanf("%s", &RecordInfo[i].Id Num);
                 break;
    
                case 4:
                 printf("Enter student's updated Date of Birth: ");
                 scanf("%d", &students[i].DateOfBirth);
                 break;
    
                case 5:
                 printf("Enter student's updated Address: ");
                 scanf("%s", &students[i].Address);
                 break;
    
                case 6:
                 printf("Enter student's updated Telephone Number: ");
                 scanf("%s", &students[i].TelephoneNumber);
                 break;
    
                case 7:
                 printf("Enter new Program: ");
                 scanf("%s", &students[i].ProgramPursued);
                 break;
    
                default:
                 printf("Wrong entry\n");
                 break;
              }
    
    
          }
       }
    }
    
    getch ();
      this is the program

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    One of the WORST mistakes a newbie can make is to write an oodle of code without TEST COMPILING. That means EVERY 5-10 LINES.

    You should never, ever, under any circumstance for any reason, be in a situation where you have just written 50-100+ lines of code and have still not tried to compile it EVEN ONCE to take care of the errors as you work. The code does not have to do anything when run. You just have to compile (to check for compile time errors) and run it (to check for runtime errors).

    That might mean having to shim some stuff in temporarily so various loose ends tie together enough. And there is no claim here, vis, I don't know how to do that. I (and probably, most) programmers never had this problem even from the beginning, so it does not require knowledge to avoid.

    What it requires is an attitude slightly above ABSOLUTE LAZINESS. You think you are being smart and saving time by not testing and shimming the code, but here you are now with a COMPLETE MESS and all that time you saved: looks like you didn't, because it will now take you MUCH LONGER to go back thru and undo your cascading stream of ignorance.

    Good luck. Other option: start over, and don't do this EVER AGAIN. However, as tabstop implies, errors often create other errors, you probably don't have that many.
    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

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    My teacher taught me to compile after writing a program then debug

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by CoreLink View Post
    My teacher taught me to compile after writing a program then debug
    I'm sorry to hear that. OTOH that advice was probably based on you being able to write a line that didn't have a syntax error in it, which does not appear to necessarily be true.

    So: You aren't allowed to use . for your own purposes; function prototypes need way more information than you have provided; code has to go somewhere (i.e. inside a function) not stranded in the middle of the file; all your grouping symbols should match, and the indentation should make it clear which pairs line up. That's a start anyway.

  7. #7
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    I am kinda confused of what you talking, lets start at the function part

  8. #8
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Your teacher is wrong. You should compile, test and debug as you write.

    What I suggest you do is delete the code you've written so far, empty the recycle bin, and start over. Do it the right way this time.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    but thats gonna take a long while to finish this, n the program isnt finsih yet but i testing whta i have so far

  10. #10
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Trust me, it's going to take longer to fix this than it is to start over.

    How long did it take you to write this? It's going to take at least that long to fix all the syntax errors. And then when you're done with that, your program is not going to work and you'll have no idea why.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  11. #11
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    how would write date of birth in a program

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by CoreLink View Post
    but thats gonna take a long while to finish this, n the program isnt finsih yet but i testing whta i have so far
    That's the point. It will take longer to fix this code than to start again, write 5 lines, make sure it works, then write 5 more. Honestly. You just don't want to believe this, and that is understandable. But it is still true.
    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

  13. #13
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    need what to write when you want the user to enter date of birth

  14. #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 06: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

  15. #15
    Registered User
    Join Date
    Apr 2010
    Posts
    26
    how would write in the struct part

Page 1 of 2 12 LastLast
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, 01:51 PM
  4. Debugging book recommendation
    By dagans in forum Projects and Job Recruitment
    Replies: 1
    Last Post: 09-13-2005, 08:35 PM
  5. debugging directx apps
    By confuted in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2003, 09:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21