please help

Discussion in 'C Programming' started by JC, Aug 15, 2003.

  1. JC

    JC Guest

    dear all,

    i have a program on hand. but i don't know how to handle the header file and
    how to get the data.

    there are three header file
    the first one is Globals.h
    #ifndef _GLOBALS_H_
    #define _GLOBALS_H_

    #include "student.h"
    #include "enrolments.h"

    StudentDatabase sdatabase;
    int student_record_count;
    EnrolmentDatabase edatabase;
    int enrolment_record_count;

    #endif

    The second one is student.h
    #ifndef _STUDENT_H_
    #define _STUDENT_H_

    typedef struct StudentData {
    char PADDING_1[3];
    char STUDENT_NUMBER[10];
    char STUDENT_LAST_NAME[15];
    char STUDENT_FIRST_NAME[11];
    } RECORD;

    typedef RECORD StudentDatabase[100];
    #endif

    the third one is enrolments.h
    #ifndef _ENROLMENTS_H_
    #define _ENROLMENTS_H_

    #include "student.h"

    typedef struct EnrolmentData {
    char ENR_STUDENT_NUMBER[10];
    char ENR_COURSE_NUMBER[5];
    char ENR_COURSE_DESCRIPTION[26];
    } ENROLMENT_RECORD;

    typedef ENROLMENT_RECORD EnrolmentDatabase[100];

    #endif

    there are three mainly .c file to handle the process.
    the main.c is like following
    #include <stdio.h>
    #include <stdlib.h>

    #include "enrolments.h"
    #include "student.h"

    int main(void) {
    printf("1 - Enrolments Management\n");
    printf("2 - Students Management\n");
    printf("\nPlease enter an option (1,2) and press <ENTER>: ");
    scanf("%d", &response);

    if response is 1 than call enrolments.c

    else
    response is 2 than call students.c

    }end

    in student.c
    #include "student.h"
    #include "globals.h"


    in enrolments.c
    #include "enrolments.h"
    #include "globals.h"
    ......
    void printStudent() {
    extern StudentDatabase sdatabase;
    extern int student_record_count;
    extern EnrolmentDatabase edatabase;
    extern int enrolment_record_count;

    printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER ); <<<<<<<<<
    what wrong with it.. why i cann't call any data back from student file row
    10 ????
    printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
    printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);

    }


    Thanks

    hope there are someone can tell me why.

    JC
     
    JC, Aug 15, 2003
    #1
    1. Advertising

  2. On Fri, 15 Aug 2003 15:17:15 +0800, "JC" <> wrote:

    >dear all,
    >
    >i have a program on hand. but i don't know how to handle the header file and
    >how to get the data.
    >
    >there are three header file
    >the first one is Globals.h
    >#ifndef _GLOBALS_H_
    >#define _GLOBALS_H_
    >
    >#include "student.h"
    >#include "enrolments.h"
    >
    >StudentDatabase sdatabase;
    >int student_record_count;
    >EnrolmentDatabase edatabase;
    >int enrolment_record_count;


    At your level, _never_ use global variables.

    If you simply refrain from that then 90% of your coding problems
    will disappear.

    Btw., note that in _C++_ any identifier that begins with an underscore
    followed by an uppercase letter is reserved for the implementation, and
    yields undefined behavior when used otherwise; I suspect the same is
    true for C.


    >#endif
    >
    >The second one is student.h
    >#ifndef _STUDENT_H_


    So this is most probably incorrect.


    >#define _STUDENT_H_
    >
    >typedef struct StudentData {
    > char PADDING_1[3];


    _Never_ use all uppercase except for macros.

    If this structure definition is provided by your teacher, as
    seems very likely (you would probably not come up with the idea
    of a padding field), then scald him or her.

    Both for all uppercase names and for the padding field.



    > char STUDENT_NUMBER[10];
    > char STUDENT_LAST_NAME[15];
    > char STUDENT_FIRST_NAME[11];
    > } RECORD;
    >
    >typedef RECORD StudentDatabase[100];
    >#endif
    >
    >the third one is enrolments.h
    >#ifndef _ENROLMENTS_H_
    >#define _ENROLMENTS_H_
    >
    >#include "student.h"
    >
    >typedef struct EnrolmentData {
    > char ENR_STUDENT_NUMBER[10];
    > char ENR_COURSE_NUMBER[5];
    > char ENR_COURSE_DESCRIPTION[26];
    >} ENROLMENT_RECORD;
    >
    >typedef ENROLMENT_RECORD EnrolmentDatabase[100];
    >
    >#endif
    >
    >there are three mainly .c file to handle the process.
    >the main.c is like following
    >#include <stdio.h>
    >#include <stdlib.h>
    >
    >#include "enrolments.h"
    >#include "student.h"
    >
    >int main(void) {
    >printf("1 - Enrolments Management\n");
    > printf("2 - Students Management\n");
    > printf("\nPlease enter an option (1,2) and press <ENTER>: ");
    > scanf("%d", &response);


    No definition of 'response'.


    >
    >if response is 1 than call enrolments.c


    This does not compile.


    >
    >else
    >response is 2 than call students.c


    This does not compile.

    >
    >}end


    This does not compile.



    >in student.c
    >#include "student.h"
    >#include "globals.h"
    >
    >
    >in enrolments.c
    >#include "enrolments.h"
    >#include "globals.h"
    >.....
    >void printStudent() {
    > extern StudentDatabase sdatabase;
    > extern int student_record_count;
    > extern EnrolmentDatabase edatabase;
    > extern int enrolment_record_count;


    You already have these declarations in a header file.



    >printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER ); <<<<<<<<<
    >what wrong with it.. why i cann't call any data back from student file row
    >10 ????


    You have not provided enough information to answer that.



    > printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
    > printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);
    >
    >}
     
    Alf P. Steinbach, Aug 15, 2003
    #2
    1. Advertising

  3. JC

    Randy Howard Guest

    In article <>, says...
    > >typedef struct StudentData {
    > > char PADDING_1[3];

    >
    > _Never_ use all uppercase except for macros.
    >
    > If this structure definition is provided by your teacher, as
    > seems very likely (you would probably not come up with the idea
    > of a padding field), then scald him or her.


    Scalding the teacher will probably get you expelled from school,
    and perhaps even arrested.

    Scolding the teacher will probably get you an F, particularly
    if you do so in front of the class.
     
    Randy Howard, Aug 15, 2003
    #3
  4. JC

    Binary Guest

    "Alf P. Steinbach" <> wrote in message
    news:...
    | Btw., note that in _C++_ any identifier that begins with an underscore
    | followed by an uppercase letter is reserved for the implementation, and
    | yields undefined behavior when used otherwise; I suspect the same is
    | true for C.

    Really? Does this have something to do with name mangling? I have been using
    the _UPPERCASE for headers =O
     
    Binary, Aug 15, 2003
    #4
  5. On Fri, 15 Aug 2003 03:15:33 -0500, Randy Howard <> wrote:

    >In article <>, says...
    >> >typedef struct StudentData {
    >> > char PADDING_1[3];

    >>
    >> _Never_ use all uppercase except for macros.
    >>
    >> If this structure definition is provided by your teacher, as
    >> seems very likely (you would probably not come up with the idea
    >> of a padding field), then scald him or her.

    >
    >Scalding the teacher will probably get you expelled from school,
    >and perhaps even arrested.


    Aha! So _that_'s what I did wrong...
     
    Alf P. Steinbach, Aug 15, 2003
    #5
  6. On Fri, 15 Aug 2003 08:18:17 GMT, "Binary" <> wrote:

    >"Alf P. Steinbach" <> wrote in message
    >news:...
    >| Btw., note that in _C++_ any identifier that begins with an underscore
    >| followed by an uppercase letter is reserved for the implementation, and
    >| yields undefined behavior when used otherwise; I suspect the same is
    >| true for C.
    >
    >Really? Does this have something to do with name mangling?


    Nope, it's in order to provide the (compiler & runtime library)
    implementor with a guaranteed non-conflicting set of names; it's
    defined by the standard.


    >I have been using the _UPPERCASE for headers =O


    Might work, might not. In _C++_ that's undefined behavior.
    Probably so in C also (does anyone know: leading underscore
    followed by uppercase?).
     
    Alf P. Steinbach, Aug 15, 2003
    #6
  7. JC

    JC Guest

    Thanks for help!..

    But the problem i met here is. i cann't find any useful information or more
    detail about how the header file working and the extern sdatabase or extern
    edatabase. and that cann't get the or access all the information from the
    student or enrolment class file. Student class file only can handle the data
    write or read from the student.dat and Enrolments class file only can handle
    the data write or read from the enrolments.dat.

    thanks

    JC
    "JC" <> wrote in message news:bhi1e9$...
    > dear all,
    >
    > i have a program on hand. but i don't know how to handle the header file

    and
    > how to get the data.
    >
    > there are three header file
    > the first one is Globals.h
    > #ifndef _GLOBALS_H_
    > #define _GLOBALS_H_
    >
    > #include "student.h"
    > #include "enrolments.h"
    >
    > StudentDatabase sdatabase;
    > int student_record_count;
    > EnrolmentDatabase edatabase;
    > int enrolment_record_count;
    >
    > #endif
    >
    > The second one is student.h
    > #ifndef _STUDENT_H_
    > #define _STUDENT_H_
    >
    > typedef struct StudentData {
    > char PADDING_1[3];
    > char STUDENT_NUMBER[10];
    > char STUDENT_LAST_NAME[15];
    > char STUDENT_FIRST_NAME[11];
    > } RECORD;
    >
    > typedef RECORD StudentDatabase[100];
    > #endif
    >
    > the third one is enrolments.h
    > #ifndef _ENROLMENTS_H_
    > #define _ENROLMENTS_H_
    >
    > #include "student.h"
    >
    > typedef struct EnrolmentData {
    > char ENR_STUDENT_NUMBER[10];
    > char ENR_COURSE_NUMBER[5];
    > char ENR_COURSE_DESCRIPTION[26];
    > } ENROLMENT_RECORD;
    >
    > typedef ENROLMENT_RECORD EnrolmentDatabase[100];
    >
    > #endif
    >
    > there are three mainly .c file to handle the process.
    > the main.c is like following
    > #include <stdio.h>
    > #include <stdlib.h>
    >
    > #include "enrolments.h"
    > #include "student.h"
    >
    > int main(void) {
    > printf("1 - Enrolments Management\n");
    > printf("2 - Students Management\n");
    > printf("\nPlease enter an option (1,2) and press <ENTER>: ");
    > scanf("%d", &response);
    >
    > if response is 1 than call enrolments.c
    >
    > else
    > response is 2 than call students.c
    >
    > }end
    >
    > in student.c
    > #include "student.h"
    > #include "globals.h"
    >
    >
    > in enrolments.c
    > #include "enrolments.h"
    > #include "globals.h"
    > .....
    > void printStudent() {
    > extern StudentDatabase sdatabase;
    > extern int student_record_count;
    > extern EnrolmentDatabase edatabase;
    > extern int enrolment_record_count;
    >
    > printf(" ID Number: %s\n", sdatabase[10].STUDENT_NUMBER );

    <<<<<<<<<
    > what wrong with it.. why i cann't call any data back from student file row
    > 10 ????
    > printf(" First Name: %s\n", sdatabase[10].STUDENT_FIRST_NAME);
    > printf(" Surname: %s\n", sdatabase[10].STUDENT_LAST_NAME);
    >
    > }
    >
    >
    > Thanks
    >
    > hope there are someone can tell me why.
    >
    > JC
    >
    >
     
    JC, Aug 15, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JC
    Replies:
    4
    Views:
    8,013
    Jeff C
    Jul 8, 2004
  2. Replies:
    4
    Views:
    545
    Chris Uppal
    May 5, 2005
  3. KK
    Replies:
    2
    Views:
    651
    Big Brian
    Oct 14, 2003
  4. MuZZy
    Replies:
    7
    Views:
    1,789
    Mike Hewson
    Jan 7, 2005
  5. mera
    Replies:
    7
    Views:
    1,131
Loading...

Share This Page