Thursday, April 30, 2009

sol tut3 ecp1026

#include
#include
#include
#define MNAME 40
struct Human{
char name[MNAME];
int id;
};

void readData(struct Human *data1,char *argv[]){
int i;
for (i=0 ; i<3; i++){
strcpy(data1[i].name,argv[2*i + 1]);
data1[i].id = atoi (argv[2*i + 2]);}
}


void printData(struct Human *data1){
int i;
for (i=0 ; i<3; i++){
printf("%s ",data1[i].name);
printf("%d\n",data1[i].id );}
}


int main(int argc, char *argv[]){

struct Human student[3];
if (argc == 7)
printf("You have entered sufficient arguments \n");
else{
fprintf(stderr, "usage %s \n", argv[0]);
return(1);
}
readData(student,argv);

printData(student);
return(0);
}

No comments: