This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdata_using_structure.c
68 lines (50 loc) · 1.72 KB
/
data_using_structure.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct bio_data{
char name[50];
int age;
char hname[70];
char city[50];
char state[50];
char country[50];
};
void fgetsCheck(char *parr,int len){ //to check and clear '\n' if it is the end of the charcter(it happens when fgets is used)
if(*(parr+(len-1))=='\n')
*(parr+(len-1))='\0';
}
int main(){
int len;
char tage[sizeof(int)];//tage for temporarly storing value of age
struct bio_data entry;
printf("Enter your name:");
fgets(entry.name,50,stdin);
len=strlen(entry.name);
fgetsCheck(entry.name,len);
printf("Enter your age:");
fgets(tage,sizeof(int),stdin);
len=strlen(tage);
fgetsCheck(tage,len);
entry.age=atoi(tage);//coverts character string tage to integer and stores it to entry.age
printf("Enter your house name:");
fgets(entry.hname,70,stdin);
len=strlen(entry.hname);
fgetsCheck(entry.hname,len);
printf("Enter the name of your city:");
fgets(entry.city,50,stdin);
len=strlen(entry.city);
fgetsCheck(entry.city,len);
printf("Enter the name of the state you are residing in:");
fgets(entry.state,50,stdin);
len=strlen(entry.state);
fgetsCheck(entry.state,len);
printf("Enter the name of the country you are residing in:");
fgets(entry.country,50,stdin);
len=strlen(entry.country);
fgetsCheck(entry.country,len);
printf("----------DATA ACCESSED FROM STRUCTURE BIO_DATA----------");
printf("\nYour name:%s",entry.name);
printf("\nYour age:%d",entry.age);
printf("\n-----Your ADDRESS-----\n\n%s,\n%s,\n%s,\n%s\n",entry.hname,entry.city,entry.state,entry.country);
return 0;
}