Orochi Avlis
08-03-2005, 10: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);
}
}
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);
}
}