PDA

View Full Version : Problem with this program, need help


Orochi Avlis
08-03-2005, 11:12 PM
I have my Unix Programming exam tomorrow.
I was doing this program to test out certain things that will be on the exam.

Anyways, long story short, it's giving me an error in line 10 (it's bolded). It says I'm passing two or variables in the function.
Which is what I'm trying to do.




#include <stdio.h>

struct student
{
char *name;
char *address;
long num;
}

int getStudent(struct student *[], int *);
void printStudent(struct student *[], int);

int main()
{
int cnt=0;
struct student *Mohawk[100];
int success;

do{
success=getStudent(Mohawk, &cnt);
if(!success)
break;
}
while(cnt<2);
printStudent(Mohawk, cnt);

}

int getStudent(struct student *s[], int *c)
{
char temp[30];
puts("Enter your name");
scanf("%s", temp);
s[*c]=(struct student*)malloc(sizeof(struct student));
if(s[*c]==NULL)
return 0;
s[*c]->name=(char*)malloc(strlen(temp));
if (s[*c]->name==NULL)
return 0;
strcpy(s[*c]->name, temp);
puts("Enter your address ");
scanf("%s",temp);

s[*c]->address=(char*)malloc(strlen(temp)+1);
if (s[*c]->address==NULL)
return 0;

strcpy(s[*c]->address,temp);

puts("Enter your student number");
scanf("%ld",&s[*c]->num);
*c+=1;
}

void printStudent(struct student *s[],int c)
{
int x;
for(x=0;x<c;x++)
{
printf("Name:%s\t Address:%s\t Number:%ld\n",s[x]->name,s[x]->address,s[x]->num);
}
}

DudeMiester
08-04-2005, 07:32 PM
I have two ideas, one don't put "struct" but maybe C is weird, or twe use "**" instead of "*[]".

Orochi Avlis
08-04-2005, 08:24 PM
It wasn't that.

I forgot the semi-colon after declaring the struct outside the main.

Also had my programming exam today.
It went really well. http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif

EDIT: Got my result.
90%. http://forums.3drealms.com/ubbthreads/images/graemlins/grin.gif
It was out of 50 marks, and I lost 5 somewhere.