write a C program to print patients' records using Structure? |
How do we write a C program to print patients' records using Structure?
C Language structure is another user-defined data type available in C that allows combining data elements of different types. Structures are used to represent a record. Like you want to keep record your books in a library.The structure can be used Keywords struct.
Book ID
Title
Subject
Author
Definition of Structure: A structure defines you must use the struct keyword in the statement. A struct keyword defines a new data type with more than one Elements. The format of the struct keyword statement.
Structure Syntax
struct [structure_Name]
{
data_type variable 1;
data_type variable 2;
data_type variable 3;
};
struct [structure_Name]
{
data_type variable 1;
data_type variable 2;
data_type variable 3;
};
Structure Syntax Example
struct Book
{
int book_id;
char book_title[100];
char book_name[100];
char book_author[100];
};
struct Book
{
int book_id;
char book_title[100];
char book_name[100];
char book_author[100];
};
How To Use Structure in C Language?
#include<stdio.h>
#include<string.h>
struct Book
{
int book_id;
char book_title[100];
char book_name[100];
char book_author[100];
};
int main( )
{
struct Book B;
B.book_id = 665407;
strcpy( B.book_title, "C Programming Language");
strcpy( B.book_name, "C Language");
strcpy( B.book_author "C E Bala Swami");
printf( "Book ID: %d\n", B.book_id);
printf( "Book Title: %s\n", B.book_title);
printf( "Book Name: %s\n", B.book_name);
printf( "Book Author: %d\n", B.book_author);
}
*****OUTPUT*****
Book ID: 665407
Book Title: C Programming Language
Book Name: C Language
Book
Author: C E Bala Swami
#include<stdio.h>
#include<string.h>
struct Book
{
int book_id;
char book_title[100];
char book_name[100];
char book_author[100];
};
int main( )
{
struct Book B;
B.book_id = 665407;
strcpy( B.book_title, "C Programming Language");
strcpy( B.book_name, "C Language");
strcpy( B.book_author "C E Bala Swami");
printf( "Book ID: %d\n", B.book_id);
printf( "Book Title: %s\n", B.book_title);
printf( "Book Name: %s\n", B.book_name);
printf( "Book Author: %d\n", B.book_author);
}
*****OUTPUT*****
Book ID: 665407
Book Title: C Programming Language
Book Name: C Language Book
Author: C E Bala Swami
Structures Function Arguments
A Structure-function argument can be used in the same way as we can pass any other variable.How To Use Structure Function in C Language?
#include<stdio.h>#include<string.h>
struct student
{
int s_id;
char sname[50];
char sfname[50];
char smname[100];
};
void printdetails( struct student s);
int main( )
{
struct student s1;
struct student s2;
s1.s_id=63633;
strcpy(s1.sname, "Jitendra");
strcpy(s1.sfname, "Sohan");
strcpy(s1.smname,"Geeta");
s2.s_id=6367833;
strcpy(s2.sname, "Rohan");
strcpy(s2.sfname, "Sohan");
strcpy(s2.smname,"Rekha");
printdetails(s1);
printdetails(s2);
return 0;
}
void print details( struct student s )
{
printf( "Student Id : %d\n", s.s_id);
printf( "Student Name : %s\n",s.sname);
printf( "Student Father Name : %s\n",s.sfname);
printf( "Student Mother Name: %s\n",s.smname);
}
*****OUTPUT*****
Student Id: 63633
Student Name : Jitendra
Student Father Name: Sohan
Student Mother Name: Geeta
Student Id: 6367833
Student Name: Rohan
Student Father Name: Sohan
Student Mother Name: Rekha
*****OUTPUT*****
Student Id: 63633
Student Name : Jitendra
Student Father Name: Sohan
Student Mother Name: Geeta
Student Id: 6367833
Student Name: Rohan
Student Father Name: Sohan
Student Mother Name: Rekha
How do we write a C program to print patient's records using Structure?
#include<studio.h>
#include<string.h>
struct parents
{
char sname[100];
char fname[100];
char mname[100];
char faddress[200];
int faddhar_num;
int fmobile_no;
int mmobil_no;
};
int main()
{
struct parents p;
strcpy(p.sname,"Shubham");
strcpy(p.fname,"Ramesh");
strcpy(p.mname,"Radhika");
strcpy(p.faddress,"Delhi");
p.faddhar_num=67574357;
p.fmobile_no=96905657;
p.mmobil_no=9787877;
printf("Student Name:%s\n",p.sname);
printf("Student Father Name:%s\n",p.fname);
printf("Student Mother Name:%s\n",p.mname);
printf("Student Father Addresd:%s\n",p.faddress);
printf("Student Father Aadhar Number:%d\n",p.faddhar_num);
printf("Student Father Mobile Number:%d\n",p.fmobile_no);
printf("Student Mother Mobile Number:%d\n",p.mmobil_no);
}
*****OUTPUT*****
Student Name: Shubham
Student Father Name: Ramesh
Student Mother Name: Radhika
Student Father Address: Delhi
Student Father Aadhar Number:67574357
Student Father Mobile Number:96905657
Student Mother Mobile Number:9787877
#include<studio.h>
*****OUTPUT*****
Student Name: Shubham
Student Father Name: Ramesh
Student Mother Name: Radhika
Student Father Address: Delhi
Student Father Aadhar Number:67574357
Student Father Mobile Number:96905657
Student Mother Mobile Number:9787877