Source: Dr. G T Raju, Professor & Head, Dept. of CSE, RNSIT
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 | #include <stdio.h> void newStrCpy(char *,char *); void newStrCat(char *,char *); void main() { char str1[80],str2[80]; int opn; do { printf("Press 1- NewStrCpy \t 2- NewStrCat\t 3- Exit\t Your Option?"); scanf("%d",&opn); switch(opn) { case 1: flushall(); printf("\n Read the Source String \n"); gets(str1); newStrCpy(str2,str1); printf(" Copied String: %s\n",str2); break; case 2: flushall(); printf(" Read the First String \n"); gets(str1); printf(" Read the Second String \n"); gets(str2); newStrCat(str1,str2); printf("Concatenated String: \n"); puts(str1); break; case 3: printf(" Exit!! Press a key . . ."); getch(); break; default: printf(" Invalid Option!!! Try again !!!\n"); break; } }while(opn != 3); } /* End of main() */ void newStrCpy(char *d,char *s) { while( (*d++ = *s++)); } void newStrCat(char *s, char *t) { while(*s) s++; while(*s++ = *t++); } |