Posted by: serial February 22, 2012
Login in to Rate this Post:
0
?
It been too many years and Now I forgot how to write C code. This is what I have done so far - check to see if there are errors - I don't have compiler to run this code and I didn't print the values - so u have to do it urself.
If this doesnot compile then - my bad -
#include <stdio.h>
#include<string.h>
struct Person {
char name[15];
int weight;
};
int main() {
struct Person p[10];
int num, i, weight;
char name1[15];
printf("\n How many items do u need to enter(1-10) ");
scanf("%d",&num);
while(num>1 || num <10) {
printf("\n Re -enter number(1-10) ");
scanf("%n"+num);
}
for(i=0; i<num; i++) {
printf("\n Enter name ");
scanf("%s",name1);
p[i].name= name1;
printf("\n Enter weight ");
scanf("%d",&weight);
p[i].weight=weight;
}
return 0;
}
If this doesnot compile then - my bad -
#include <stdio.h>
#include<string.h>
struct Person {
char name[15];
int weight;
};
int main() {
struct Person p[10];
int num, i, weight;
char name1[15];
printf("\n How many items do u need to enter(1-10) ");
scanf("%d",&num);
while(num>1 || num <10) {
printf("\n Re -enter number(1-10) ");
scanf("%n"+num);
}
for(i=0; i<num; i++) {
printf("\n Enter name ");
scanf("%s",name1);
p[i].name= name1;
printf("\n Enter weight ");
scanf("%d",&weight);
p[i].weight=weight;
}
return 0;
}