Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
TeleBook2
//gcc 7.4.0 //TeleBook2: example of nested switch and nested structure blended with function returning structure and function taking structure as parameter. //this code is created by Rezaul Hoque on March 23,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 var1,var2,var3; var1=proform(); var2=procur(); var3=personal(); int a,b; printf("Select: \n"); printf("(1)Professional (2) Personal\n"); scanf("%d",&a); switch(a){ case 1: printf("Select:\n"); printf("(1)Former Coworkers (2)Current Coworkers\n"); scanf("%d",&b); switch(b){ case 1: printf("Former Office Coworker Contacts:\n"); display(var1); break; case 2: printf("Current Office Coworker Contacts:\n"); display(var2); break; } break; case 2: printf("Personal Contacts:\n"); display(var3); break; } return 0; }
run
|
edit
|
history
|
help
0
PUNTEROS 1
CO Assignment 1 Question 4
Area and Volume coding
A_141124Burbuja
Divisibility :- #simple-math #ad-hoc-1 #basics
Adding sums of two 1-D arrays
150108_recursividadFactorial
Sirali_mi_fonksyonu
B_141121_aleatorios
double_buffer_madness