bigtamscot
Programmer
Hi, I am studying C, and i am having problems with a project I have to complete and hand in for marking asap. The trouble is with multi-dimensional string tables. I have to create a list of student names and the course they are enrolled in at college. Here is a snippet of what I have so far:-
int void main( )
{
char student[MAX][30], char course[MAX][30];
char *s_ptr, *c_ptr;
int i;
s_ptr = student; c_ptr = course;
for(i = 0; i < MAX - 1;i++)
{
printf("Enter students name\n"
gets(*s_ptr);
printf("Enter course student has enrolled in\n"
gets(*c_ptr);
s_ptr++; c_ptr++;
}
*s_ptr = '\0'; /*add null string*/
c_ptr = course;
for(s_ptr=student; s_ptr ; s_ptr++)
{
puts(*s_ptr);
puts(*c_ptr);
c_ptr++;
}
}
What I would like to be able to do is to create a multi dimensional string table to store both students name and course, like so.
char student_details[MAX][30][30] = {
{"Joe Bloggs", "History"},
{ "ect", "ect" }
}
The only trouble is that all examples I have in course material only cover string tables like these which have been initialized with entries. I would like to allow user to enter names and course details straight in to this table,and then display the tables, either by conventional means or by pointers. The truth is i have no idea how to go about this any help will be appreciated. Try to remember this is course material, and I have only to use functions we have covered so far, so this excludes function calls, files or malloc. I have just completed pointers (though not in great detail.
Thanks in advance,
bigtamscot Hoping to get certified..in C programming.
int void main( )
{
char student[MAX][30], char course[MAX][30];
char *s_ptr, *c_ptr;
int i;
s_ptr = student; c_ptr = course;
for(i = 0; i < MAX - 1;i++)
{
printf("Enter students name\n"
gets(*s_ptr);
printf("Enter course student has enrolled in\n"
gets(*c_ptr);
s_ptr++; c_ptr++;
}
*s_ptr = '\0'; /*add null string*/
c_ptr = course;
for(s_ptr=student; s_ptr ; s_ptr++)
{
puts(*s_ptr);
puts(*c_ptr);
c_ptr++;
}
}
What I would like to be able to do is to create a multi dimensional string table to store both students name and course, like so.
char student_details[MAX][30][30] = {
{"Joe Bloggs", "History"},
{ "ect", "ect" }
}
The only trouble is that all examples I have in course material only cover string tables like these which have been initialized with entries. I would like to allow user to enter names and course details straight in to this table,and then display the tables, either by conventional means or by pointers. The truth is i have no idea how to go about this any help will be appreciated. Try to remember this is course material, and I have only to use functions we have covered so far, so this excludes function calls, files or malloc. I have just completed pointers (though not in great detail.
Thanks in advance,
bigtamscot Hoping to get certified..in C programming.