/* This program is a demonstration of string operations and string functions available in C. */ #include <stdio.h> char *name[]={"James","Kirk"}; main() { /* Declaration Statements */ char group[16]; short i,age; /* Assignment Statements */ clrscr(); printf("C351.C -> Demonstration of string operations.\n"); printf("\nEnter Age of James : "); scanf("%hd", &age); if (age < 18) strcpy(group, "minor"); else { if (age < 35) strcpy(group, "prime years"); else strcpy(group, "mature"); } /* End of else{} statement */ i=1; /* Print Results */ printf("\nResult: %s 's age is %s\n", name[i-1], group); printf("---------------------------------\n"); printf("Enter Age of Kirk : "); scanf("%hd", &age); if (age < 18) strcpy(group, "minor"); else { if (age < 35) strcpy(group, "prime years"); else strcpy(group, "mature"); } /* End of else{} statement */ i++; /* Print results */ printf("\nResult: %s 's age is %s\n", name[i-1], group); printf("\n---------------------------------\n\n"); return(0); } /* End of Program C351 */ /* Input : 3 25 Output : C351.C -> Demonstration of string operations. Enter Age of James : 3 Result: James 's age is minor --------------------------------- Enter Age of Kirk : 25 Result: Kirk 's age is prime years --------------------------------- */
Last modified: 28/07/97