i would like to write a program in C language that takes the details of a person eg. name address age telephone number etc.. by using structures.. and be able to display the whole information or details on the screen.
In C Language, HOW DO i STORE FOR Eg. DETAILS OF A PERSON USING STRUCTURES AND DISPLAY ALL DETAILS ON SCREEN?
/*set up a struct like so:*/
#include %26lt;stdlib.h%26gt;
#include %26lt;stdio.h%26gt;
int main()
{
struct person
{
char name[30], address[50];
int age,telephone;
};
/*variable of type persons*/
struct person details;
/*read*/
printf("Name:");
fgets(details.name, 30,stdin);
printf("Address:");
fgets(details.address,50,stdin);
printf("Age:");
scanf("%d",%26amp;(details.age));
printf("Number:");
scanf("%d",%26amp;(details.telephone));
/*print*/
printf("\nprinting data");
printf("Name: %s",(details.name));
printf("Address: %s",(details.address));
printf("Age: %d\n",(details.age));
printf("Number: %d\n",(details.telephone));
return 0;
}
/* subtle things to note, use fgets when someone might include a space in their input, but remember fgets will store the \n character, so keep that in mind when printing it */
yu gi oh cards
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment