Thread: Need Help Please

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    12

    Need Help Please

    Hi, New Here
    Im trying to do the instructions below, but when I enter my code, I can run through the B-number, but the rest of the values dont seem to do anything. I think I have created the dynamic array correctly, but I am unsure if I am using it right.

    This is how I did my dynamic array:

    typedef struct Record{
    unsigned int bNumber;
    char firstName[19];
    char lastName[19];
    char quizGrades[6];
    char projectGrades[5];
    char finalExamGrade;
    struct Record *next;
    }Record;


    Here is a copy of my code:

    Record* list;
    void Input(void){
    int i;
    Record *tailRecord;
    while(1){
    Record *newRecord = (Record*) malloc(sizeof(Record));
    printf("Please Enter Students B-Number:\n");
    scanf("%d",&newRecord->bNumber);
    printf("Please Enter Students First Name:\n");
    scanf("%18s",newRecord->firstName);
    printf("Please Enter Students Last Name:\n");
    scanf("%18s",newRecord->lastName);
    for(i = 0; i < 6; i++)
    printf("Please Enter Students Grade For Quiz # %d\n",i);
    scanf("%d", (int*)&newRecord->quizGrades[i]);
    for(i = 0; i < 5; i++)
    printf("Please Enter Students Grade For Project # %d\n",i);
    scanf("%d", (int*)&newRecord->projectGrades[i]);
    printf("Please Enter Student's Final Exam Grade");
    scanf("%d",(int*)&newRecord->finalExamGrade);

    }
    }





    Instructions:
    Create a C struct used to store data for a student in this class, as part of a dynamic array. The data for a student must include:

    B-Number (as an 'unsigned int')
    First name (up to 18 characters, not inluding the NULL)
    Last name (also up to 18 characters, not inluding the NULL)
    6 quiz grades
    5 project grades
    Final exam grade
    Each 'grade' should be a 'char' (either signed or unsigned, your choice) type, since it can only range from 0 to 100, inclusive. The definition for this struct should be written in your stlist.h header file.

    Define a static global "list" pointer for this array, and a set of functions for manipulating this list in your stlist.c file. A declaration for each of these functions - along with detailed descriptions of each, should be placed in the stlist header file. You must provide, with the functions in this file, at least the following functionality:
    Last edited by Ekrish; 12-11-2009 at 02:49 PM.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    woops my bad

  4. #4
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    Code:
    Record* list;
    void Input(void){
       int i;
       Record *tailRecord;
       while(1){
        Record *newRecord = (Record*) malloc(sizeof(Record));
    
        printf("Please Enter Students B-Number:\n");
        scanf("%d",&newRecord->bNumber);
    
        printf("Please Enter Students First Name:\n");
        scanf("%18s",newRecord->firstName);
    
        printf("Please Enter Students Last Name:\n");
        scanf("%18s",newRecord->lastName);
        
        for(i = 0; i < 7; i++)
        {
        printf("Please Enter Students Grade For Quiz # %d\n",i);
        scanf("%d", (int*)&newRecord->quizGrades[i]);
        }
        
        for(i = 0; i < 6; i++)
        {
        printf("Please Enter Students Grade For Project # %d\n",i);
        scanf("%d", (int*)&newRecord->projectGrades[i]);
        }
    
        printf("Please Enter Student's Final Exam Grade");
        scanf("%d",(int*)&newRecord->finalExamGrade);
    
    
        printf("%d",newRecord->bNumber);
        printf("%s",newRecord->firstName);
        printf("%s",newRecord->lastName);
        for(i=0; i<7;i++)
        {
        printf("%d",newRecord->quizGrades[i]);
        }
        for(i=0;i<6;i++)
        {
            printf("%s",newRecord->projectGrades[i]);
        }
        printf("%s",newRecord->finalExamGrade);
    
    
        newRecord->next=NULL;
          
           if(!list)
               {list = newRecord;tailRecord = list;}
           else{
               tailRecord->next = newRecord;
               tailRecord = tailRecord->next;
           }
           
    
    }
    }

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    alright ive been workin on it for a bit, and here is what I have now:
    Code:
    Record* list;
    void Input(void){
       int i;
       Record *tailRecord;
       while(1){
        Record *newRecord = (Record*) malloc(sizeof(Record));
    
        printf("Please Enter Students B-Number:\n");
        scanf("%d",&newRecord->bNumber);
    
        printf("Please Enter Students First Name:\n");
        scanf("%s",&newRecord->firstName);
        
        printf("Please Enter Students Last Name:\n");
        scanf("%s",&newRecord->lastName);
        
        for(i = 0; i < 7; i++)
        {
        printf("Please Enter Students Grade For Quiz # %d\n",i);
        scanf("%s", (int*)&newRecord->quizGrades[i]);
        }
        
        for(i = 0; i < 6; i++)
        {
        printf("Please Enter Students Grade For Project # %d\n",i);
        scanf("%s", (int*)&newRecord->projectGrades[i]);
        }
    
        printf("Please Enter Student's Final Exam Grade:\n");
        scanf("%s",(int*)&newRecord->finalExamGrade);
    
    
        printf("%d\n",newRecord->bNumber);
        
        printf("%s\n",&newRecord->firstName);
        
        printf("%s\n",&newRecord->lastName);
    
        for(i=0; i<7;i++)
        {
        printf("%s\n",newRecord->quizGrades[i]);
        }
    
        for(i=0;i<6;i++)
        {
            printf("%s\n",newRecord->projectGrades[i]);
        }
    
        printf("%s\n",newRecord->finalExamGrade);
    
    
        newRecord->next='\0';
          
           if(!list)
               {list = newRecord;tailRecord = list;}
           else{
               tailRecord->next = newRecord;
               tailRecord = tailRecord->next;
           }
           
    
    }
    }

    when I run it this is what i get

    Code:
    Please Enter Students B-Number:
    b00190483
    Please Enter Students First Name:
    Please Enter Students Last Name:
    evan
    Please Enter Students Grade For Quiz # 0
    4
    Please Enter Students Grade For Quiz # 1
    334
    Please Enter Students Grade For Quiz # 2
    34
    Please Enter Students Grade For Quiz # 3
    
    45
    Please Enter Students Grade For Quiz # 4
    45
    Please Enter Students Grade For Quiz # 5
    34
    Please Enter Students Grade For Quiz # 6
    534
    Please Enter Students Grade For Project # 0
    534
    Please Enter Students Grade For Project # 1
    534
    Please Enter Students Grade For Project # 2
    534
    Please Enter Students Grade For Project # 3
    534
    Please Enter Students Grade For Project # 4
    54
    Please Enter Students Grade For Project # 5
    54
    Please Enter Student's Final Exam Grade:
    545
    0
    b00190483
    evan
    /Applications/NetBeans/NetBeans 6.7.1.app/Contents/Resources/NetBeans/dlight1/bi
    n/nativeexecution/dorun.sh: line 51:  8816 Segmentation fault      /bin/sh "${PI
    DFILE}.sh"
    Press [Enter] to close the terminal ...

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
        for(i = 0; i < 7; i++)
        {
        printf("Please Enter Students Grade For Quiz # %d\n",i);
        scanf("%d", (int*)&newRecord->quizGrades[i]);
        }
    quizGrades is defined as:
    char quizGrades[6];
    That means you have 6 indexes, but your for loop is attempting to insert 7 values. Also, the scanf() should look like this instead:
    Code:
    scanf("%c", &newRecord->quizGrades[i]);
    Use %c instead of %s since you are expecting the user to input a single character instead of a string. Same thing when you print out the characters down below.
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    wow I cant believe I didnt see that, thanks alot

  8. #8
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    wait, but I am looking for two character input i.e 85, would that still work?

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You might also want to take a look at SourceForge.net: Scanf woes - cpwiki
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    One of my big problems is this:
    Code:
    Please Enter Students B-Number:
    b00190483
    Please Enter Students First Name:
    Please Enter Students Last Name:
    evan
    Please Enter Students Grade For Quiz # 0
    when first name is suppose to be entered, it gets skipped and jumps directly to last name. I have no idea what is going on, i cannot find a problem.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A common problem. Read my link for some helpful information.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    Thanks Again, I got that part running smoothly. This is a continuing project, so Ill keep you guys updated on my stress.

  13. #13
    Registered User
    Join Date
    Dec 2009
    Posts
    12
    This is my next task:

    define a static global "list" pointer for this array, and a set of functions for manipulating this list in your stlist.c file. A declaration for each of these functions - along with detailed descriptions of each, should be placed in the stlist header file. You must provide, with the functions in this file, at least the following functionality:

    Input, from the user, a set of student data for one student. Verify this data is valid (not a duplicate B-Number, all grades from 0-100, etc...). If it is, add it to the end of the list.

    Remove the last student from the list.

    Print the list of students, plus all calculated grades (see note below) for each student.

    Remove a student by b-number (input by the user).

    Print all the info of a student by b-number (input by the user), plus all calculated grades (see note below).

    Sort the list by students' last names (then first names, if the last names are the same - then B-Number if both names are the same) using the Bubble Sort algorithm.

    Save the entire list to a text file (see note below). The filename should be requested from the user.

    Load (and replace) the entire list from a text file (see note below). The filename should be requested from the user.

    Load an initial list from a file specified on the command-line as the first (and only) command-line argument. If no file is specified, the list should initially be empty.


    I am completely lost on how to tackle those tasks

  14. #14
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by Ekrish View Post
    This is my next task:
    You are allowed to make new threads for completely new topics such as this one...


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed