#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    1
    Rep Power
    0

    Data structure and algorithm


    hi... i'm currently doing my coding on structure in C... but i found there is an error in my last void function...i'm asking for your help because i don't know what else to do :( .. thank you in advance for any help :)

    Code:
    #include <stdio.h> #include <conio.h> #include <stdlib.h> struct student { char student_name[50]; char matrix_id[10]; char course[10]; char project_title[100]; char field[20]; char supervisor[50]; }; struct student addname(); void list_func(student); int main() { struct student student1,student2; student1=addname(); student2=addname(); printf("\n\n\tUNDERGRADUATE PROJECT RECORD SYSTEM"); list_func(student1); list_func(student2); getch(); } struct student addname() { struct student pelajar; printf("\n\nEnter students's name: "); gets(pelajar.student_name); printf("\nEnter Matrix ID: "); gets(pelajar.matrix_id); printf("\nEnter Course: "); gets(pelajar.course); printf("\nEnter project title: "); gets(pelajar.project_title); printf("\nEnter field: "); gets(pelajar.field); printf("\nEnter supervisor name: "); gets(pelajar.supervisor); return (pelajar); } void list_func(student list) { printf("\n\nStudent's Name: %s",list.student_name); printf("\nMatrix ID: %s",list.matrix_id); printf("\n\nCourse: %s",list.course); printf("\nProject's Title: %s",list.project_title); printf("\n\nField: %s",list.field); printf("\nSupervisor: %s",list.supervisor); return; }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Posts
    159
    Rep Power
    19
    Please repost your code so it is readable. Also you should never use the gets() function. This function is considered very unsafe and should be replaced with a function that limits the number of characters that will be accepted, like fgets().

    Jim
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    If there is an error, shouldn't you tell us what it is instead of trying to force us to play stupid guessing games?

    Compiler error? What is the exact wording of the error message and for what line of the source code was it issued?

    Warnings? What warning messages are you getting? Exact wording and line number.

    Unexpected behavior? What behavior did you expect and what exactly is it doing instead?

    You would not go to the doctor deathly sick and make him guess what symptoms you're feeling, would you? So why do that to us?

    Your code is completely unreadable, so I didn't even bother to look at it. Reformat it with newlines and don't give up until you can see for yourself that it is readable. You could see for yourself when you posted it that it was all messed up, so why did you leave it that way? And be sure to indent your code properly.
    Last edited by dwise1_aol; March 19th, 2013 at 03:05 PM.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,255
    Rep Power
    2222
    BTW, I have taken the time out of my busy work schedule to convert your unreadable mess into a code listing. In that readable form, your problem is immediately apparent. However, we must wait until you have presented us with a readable form of your program before I can inform you of what I had found. So do please hurry up and correct your post so that you won't waste any more time.

    In the meantime, here is what my compiler (MinGW gcc) thought of your code:
    C:TEST>gcc -Wall pelajar.c
    pelajar.c:17: warning: parameter names (without types) in function declaration
    pelajar.c: In function `main':
    pelajar.c:29: warning: control reaches end of non-void function
    pelajar.c: At top level:
    pelajar.c:50: parse error before `list'
    pelajar.c: In function `list_func':
    pelajar.c:52: `list' undeclared (first use in this function)
    pelajar.c:52: (Each undeclared identifier is reported only once
    pelajar.c:52: for each function it appears in.)

    C:TEST>
    Do not ignore the warnings. Never ignore warnings. Warnings can be far more important than error messages.

    "pelajar.c:29: warning: control reaches end of non-void function" means that you left out the return statement at the end of main. Return zero for normal operation and non-zero if the program encountered a problem (eg, it failed to open a file, it was given the wrong command-line arguments). Most of the time for such simple programs you would always just return zero.

IMN logo majestic logo threadwatch logo seochat tools logo