Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
FunPointTeleBook
//gcc 7.4.0 //FunPointTeleBook: example of function pointer and nested structure blended with function returning structure and function taking structure as parameter. //this code is created by Rezaul Hoque on March 30,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 <stdlib.h> #include <string.h> #define SZ 2 struct person{ char first[30]; char last[30]; int num; }; struct tele { char category[30]; struct person p[SZ]; }tel; struct tele proform(); struct tele procur(); struct tele personal(); void display(struct tele t); struct tele proform(){ strcpy( tel.p[0].first,"www"); strcpy( tel.p[0].last,"ccc"); tel.p[0].num=2222; strcpy(tel.category,"Former Coworker"); strcpy( tel.p[1].first,"aaa"); strcpy( tel.p[1].last,"tttt"); tel.p[1].num=5555; strcpy(tel.category,"Former Coworker"); return tel; } struct tele procur(){ strcpy( tel.p[0].first,"uuu"); strcpy( tel.p[0].last,"ffff"); tel.p[0].num=3216; strcpy(tel.category,"Current Coworker"); strcpy( tel.p[1].first,"bbb"); strcpy( tel.p[1].last,"zzz"); tel.p[1].num=6543; strcpy(tel.category,"Current Coworker"); return tel; } struct tele personal(){ strcpy( tel.p[0].first,"SSS"); strcpy( tel.p[0].last,"YYY"); tel.p[0].num=4321; strcpy(tel.category,"Personal"); strcpy( tel.p[1].first,"III"); strcpy( tel.p[1].last,"PPP"); tel.p[1].num=01234; strcpy(tel.category,"Personal"); return tel; } void display(struct tele t){ printf("Name Phone Number Category \n"); for(int i=0;i<SZ;i++) printf("%s %s %d %s\n",t.p[i].first,t.p[i].last,t.p[i].num, t.category); } int main() { struct tele t; struct tele (*p[3])(); p[0]=proform; p[1]=procur; p[2]=personal; int c; printf("Select: \n"); printf("(0)Former Coworkers (1)Current Coworkers (2)Personal\n"); scanf("%d",&c); switch(c){ case 0: printf("Former Office Coworker Contacts:\n"); break; case 1: printf("Current Office Coworker Contacts:\n"); break; case 2: printf("Personal Contacts:\n"); break; } t=(*p[c])(); display(t); return 0; }
run
|
edit
|
history
|
help
0
a3
Length width.c
Assignment 4 v3
Square pyramid
HW2A
My first program
Float data type.c
Strncpy memcpy
Finding the second largets value v0.5
project menu