Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
StructSurvey
//gcc 7.4.0 //StructSurvey: example of bit field,function pointer,function returning structure and function taking structure as parameter //this code is created by Rezaul Hoque on April 02,2022;contact: jewelmrh@yahoo.com,Dhaka, Bangladesh //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> #include <string.h> struct survey{ char name[20]; unsigned int age:6; unsigned gender:1; unsigned vac:1; unsigned boost:1; unsigned eatout:1; unsigned resto:1; unsigned road:1; }; struct survey input(); void display(struct survey); struct survey input () { struct survey bit; strcpy(bit.name,"AAA ZZZ"); bit.age=25; bit.gender=1; bit.vac=1; bit.boost=0; bit.eatout=1; bit.resto=1; bit.road=0; return bit; } void display(struct survey bit){ printf("Name: %s\n",bit.name); printf("Age: %d\n",bit.age); if(bit.gender) printf("Gender: Male.\n"); else printf("Gender: Female.\n"); if(bit.vac) printf("Vaccinated.\n"); else printf("Not vaccinated.\n"); if(bit.boost) printf("Got booster dose.\n"); else printf("Yet to get a booster dose.\n"); if(bit.eatout) printf("One or more eatout in the last six months.\n"); else printf("No eatout in the last six months.\n"); if(bit.resto) printf("Take food at a restaurant in the last six months.\n"); else printf("No dine out at a restaurant in the last six months.\n"); if(bit.road) printf("Take food at a roadside stall in the last six months.\n"); else printf("No eating at a roadside stall in the last six months.\n"); } int main(void) { struct survey s; struct survey (*p)(); p=input; s=(*p)(); display(s); return 0; }
run
|
edit
|
history
|
help
0
1233333
Is const really const?
string_ptr_to_fct_param
Project 3 Part 1 v2.1
numeroleidodeordeninverso
4qwrfdsfsaf
709 lab 3.1
project menu
PRIMER PROGRAMA CON MALLOC()
Assignment 7