In this program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct person{
char name[30];
char address[30];
int phoneNumber[30];
char creditRating[30];
};
int main(){
struct person p;
printf("What is the person's name?\n");
scanf(" %s", p.name);
printf("What is the person's address?\n");
scanf(" %s", p.address);
printf("What is the person's phone number?\n");
scanf("%d", &p.phoneNumber);
printf("What is the person's credit rating?\n");
scanf(" %s", p.creditRating);
printf("The person's name is %s\n", p.name);
printf("The person's address is %s\n", p.address);
printf("The person's phone number is %d\n", p.phoneNumber);
printf("The person's credit rating is %s\n", p.creditRating);
return 0;
}
Can I have something like
For(i=0;i>=n;i++)
struct person [i];
printf("What is the person's name?\n");
scanf(" %s", [i].name);
printf("What is the person's address?\n");
scanf(" %s", [i].address);
printf("What is the person's phone number?\n");
scanf("%d", &[i].phoneNumber);
printf("What is the person's credit rating?\n");
scanf(" %s", [i].creditRating);
I want to have 100 structs with their inputs. It's a bit hard to write them one by one like:
struct person p;
.....
struct person q;
.....
//and etc...
How can I avoid that?