Ok, i really need to do some studying here.
I'm really confused right now with structures and classes.
And to ice the cake our teacher likes to really confuse the topic by using several unfamiliar coding styles.
If anyone know of any good online resources that really helps for a person relatively new to structures and classes please post them here//
This is just an example of what we are doing, not really meaningful code
typedef struct student
{
char* psurname;
char* pgiven1;
char* pstudnum;
double gpa;
} STUD;
STUD* make_student (void)
{
STUD* pstud = NULL;
char dummy[80];
clrscr ();
printf ("Surname: ");
gets (dummy);
if (*dummy != '\0'); // if null string not entered
{
pstud = (STUD*) malloc (sizeof (STUD));
if (pstud == NULL)
printf ("\n*** Cannot create new student ***");
else
{
psurname = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->psurname, dummy);
printf ("\nGiven name: ");
gets (dummy);
pgiven1 = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->pgiven1, dummy);
printf ("\nStudent number: ");
gets (dummy);
pstudnum = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->pstudnum, dummy);
printf ("\nGPA:");
gets (dummy);
if (strlen (dummy) == 0) // another test for null string
pstud->gpa = 0.0;
else
pstud->gpa = atof (dummy); // string to double
}
}
return (pstud);
}
I'm really confused right now with structures and classes.
And to ice the cake our teacher likes to really confuse the topic by using several unfamiliar coding styles.
If anyone know of any good online resources that really helps for a person relatively new to structures and classes please post them here//
This is just an example of what we are doing, not really meaningful code
typedef struct student
{
char* psurname;
char* pgiven1;
char* pstudnum;
double gpa;
} STUD;
STUD* make_student (void)
{
STUD* pstud = NULL;
char dummy[80];
clrscr ();
printf ("Surname: ");
gets (dummy);
if (*dummy != '\0'); // if null string not entered
{
pstud = (STUD*) malloc (sizeof (STUD));
if (pstud == NULL)
printf ("\n*** Cannot create new student ***");
else
{
psurname = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->psurname, dummy);
printf ("\nGiven name: ");
gets (dummy);
pgiven1 = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->pgiven1, dummy);
printf ("\nStudent number: ");
gets (dummy);
pstudnum = (char*) malloc (strlen (dummy) + 1);
strcpy (pstud->pstudnum, dummy);
printf ("\nGPA:");
gets (dummy);
if (strlen (dummy) == 0) // another test for null string
pstud->gpa = 0.0;
else
pstud->gpa = atof (dummy); // string to double
}
}
return (pstud);
}