Need help on C

This is a discussion on Need help on C within the C Programming forums, part of the General Programming Boards category; Hi, im doing homework in C programming, the programme is about "incourse assessment system". Does anybody have similar example on ...

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    12

    Unhappy Need help on C - looking for coding sample

    Hi, im doing homework in C programming, the programme is about "incourse assessment system".

    Does anybody have similar example on the above topic, can you please help me. I need to see sample coding. Please.. urgent...
    Last edited by elfreakz; 04-19-2005 at 09:55 AM.

  2. #2
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    the programme is main for lecturer to key in and view, the marks of any assessment of the student (test 1, assignment, and test 2). It is for 12 student only.

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Quote Originally Posted by kermi3
    Homework Policy:

    The purpose of these board is not for other people to do your homework for you. Try things out work on your own, homework has a purpose. If you still have trouble with a specific piece of code or concept please feel free to ask. But please do not ask people to do your entire homework for you, it simply annoys people most of the time.

    For an example check out this thread written by Prelude. Thanks Prelude.

    If you are looking for someone to do an entire problem for you, we recommend that you use the site's Ask an Expert service. Please note: We strongly discourage people from cheating. It is there for personal and non-graded problems that are not answered on the message boards.

    If you have any questions about what is approprate, or anything else, please E-mail or PM me and I'll be happy to answer them.

    Thank you

    Kermi3
    Lead Moderator
    Post some code and we can help you, but we're not here to do your homework for you.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    [tag]
    Code:
    #include <stdio.h>
    #include <iostream.h>
    
    void test1();
    void test1_marks();
    void test1_view_marks();
    void back_to_main_menu();
    
    
    void main()
    {
    	test1();
    }
    
    void test1()
    {
    	char choice;
    	
    	printf ("\n############################################\n");
    	printf ("\nTest 1\n");
    	printf ("\n############################################\n");
    	printf ("\n[1] Enter Marks\n[2] View Marks\n[3] Back to Main Menu\n\n\n");
    	printf ("You Choose:");
    	scanf ("choice");
    
    	if ( choice == '1')
    	{
    		test1_marks();
    	}
    	
    	else if ( choice == '2')
    	{
    		test1_view_marks();
    	}
    
    	else if ( choice == '3')
    	{
    		back_to_main_menu();
    	}
    }
    
    void test1_marks()
    {
    	struct studentData {
    		char studentname [8];
    		int studentmark;
    	};
    	{
    
    		FILE *cfPtr;
    		struct studentData blankClient = { "", 0, };
    
    		if (( cfPtr = fopen ("credit.dat", "r+")) == NULL )
    			printf ( "File could not be opened.\n");
    		else {
    			printf ( "Enter Student Name\n?" );
    			fscanf ( stdin, "%s%s%slf", blankClient.studentname );
    
    			while ( blankClient.studentname != 0 ) {
    				printf ( "Enter Student Mark:\n" );
    				fwrite ( &blankClient, sizeof (struct studentData), 1, cfPtr );
    			}
    
    			fclose( cfPtr );
    		}
    }
    return 0;
    
    }
    [/tag]

    this is half of it. i seem dont understand anything.. gosh.. alot of errors...

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    scanf ("choice");
    should be
    scanf ("%c", &choice);

    main()'s return type is int, not void

    If you post your errors, it'll be easier for us to help you.

  6. #6
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Linking...
    TEST1.obj : error LNK2001: unresolved external symbol _back_to_main_menu
    TEST1.obj : error LNK2001: unresolved external symbol _test1_view_marks
    Debug/TEST1.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    TEST1.exe - 3 error(s), 0 warning(s)

  7. #7
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    i need to get TEST 1 screen to work, then TEST 2 and ASSIGNMENT screen will only need to change alil bit of TEST 1... hopefully someone can help me

  8. #8
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    You haven't defined
    void test1_view_marks();
    void back_to_main_menu();

    If this is supposed to be pure C code, don't include <iostream.h>. If this assignment can be done in C++, then there are much easier ways to go about certain things.

    And a void function doesn't return 0 or any other value. If you like, you can write a return statement like so:
    return;

  9. #9
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Code:
    #include <stdio.h> 
     
    void test1(); 
    void test1_marks(); 
    void test1_view_marks(); 
    void back_to_main_menu(); 
     
     
    void main() 
    { 
         test1(); 
       
    } 
     
    void test1() 
    { 
         char choice; 
          
         printf ("\n############################################\n"); 
         printf ("\nTest 1\n"); 
         printf ("\n############################################\n"); 
         printf ("\n[1] Enter Marks\n[2] View Marks\n[3] Back to Main Menu\n\n\n"); 
         printf ("You Choose:"); 
         scanf ("choice"); 
     
         if ( choice == '1') 
         { 
              test1_marks(); 
         } 
          
         else if ( choice == '2') 
         { 
              test1_view_marks(); 
         } 
     
         else if ( choice == '3') 
         { 
              back_to_main_menu(); 
         } 
    }
    void test1_marks() 
    { 
         struct studentData { 
              char studentname [8]; 
              int studentmark; 
         }; 
     
              FILE *cfPtr; 
              struct studentData blankClient = { "", 0, }; 
     
              if (( cfPtr = fopen ("credit.dat", "r+")) == NULL ) 
                   printf ( "File could not be opened.\n"); 
              else { 
                   printf ( "Enter Student Name\n?" ); 
                   fscanf ( stdin, "%s%s%slf", blankClient.studentname ); 
     
                   while ( blankClient.studentname != 0 ) { 
                        printf ( "Enter Student Mark:\n" ); 
                        fwrite ( &blankClient, sizeof (struct studentData), 1, cfPtr ); 
                   } 
     
                   fclose( cfPtr ); 
     }
    }
    
    void test1_view_marks()
    {
    }
    
    void back_to_main_menu()
    {
    }
    this code looks ok now.. but why when i choose 1, it suddently close?

  10. #10
    Registered User
    Join Date
    May 2004
    Posts
    114
    you need to get input / make it pause to stop it suddenly quiting. Also I think theres an extra } at the end of void test1_marks()

  11. #11
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Quote Originally Posted by kzar
    you need to get input / make it pause to stop it suddenly quiting. Also I think theres an extra } at the end of void test1_marks()

    i dont get u clearly kzar

  12. #12
    Registered User
    Join Date
    Feb 2005
    Posts
    26
    Show me the contents of the input file and I can try to fix it.

  13. #13
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    Pressure, the contents of the input file would look like:-

    TEST 1

    [1] Enter Marks --> will be link to another screen which will ask user to input 12 student ID and Marks, else back to TEST 1 screen.
    [2] View Marks --> will view all marks else back to TEST 1 screen
    [3] Back To Main Menu

    -> i dont really know how to use database, i believe for this kind of question i need to use file processing and database right?

  14. #14
    Registered User
    Join Date
    Apr 2004
    Posts
    173
    A couple of things:
    Code:
     fscanf ( stdin, "%s%s%slf", blankClient.studentname );
    I'm pretty sure you just want to get a string into studentname so you only need 1 "%s" format modifier.

    Also change the return value of main into an int not void - this has already been mentioned.

    The program also exits because you failed to change the scanf("choice"); again this has already been mentioned earlier. You would want something like:
    Code:
    scanf("%c",&choice);
    Please read the previous posts and make changes instead of just ignoring them.
    The cost of software maintenance increases with the square of the programmer's creativity.

  15. #15
    Registered User
    Join Date
    Apr 2005
    Posts
    12
    oh my god, that is so confuse!

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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