#include <stdio.h> #include <stdlib.h> #include <string.h> #define Beta "Beta" #define Num_Beta 2 #define Gamma "Gamma" #define Num_Gamma 3 #define Delta "Delta" #define Num_Delta 4 #define Epsilon "Epsilon" #define Num_Epsilon 5 #define Alpha "Alpha" #define Num_Alpha 1 #define CHANGE(NAME) if(srcindex + strlen(NAME) > length){/ strcpy((char*)&dest[destindex], (char*)&src[srcindex]);/ destindex += strlen((char*)&src[srcindex])+1;/ srcindex = length;/ }else {/ temp = src[srcindex+strlen(NAME)];/ src[srcindex+strlen(NAME)] = '/0';/ if( strcmp( (char*)&src[srcindex], NAME ) == 0 ){/ dest[destindex] = Num_##NAME+'0';/ destindex++;/ srcindex += strlen(NAME);/ src[srcindex] = temp;/ }else {/ dest[destindex] = src[srcindex];/ src[srcindex+strlen(NAME)] = temp;/ srcindex++;/ } / } void main(){ char src[1000] = "( Beta, ( Gamma, ( Delta , Epsilon ) ), Alpha )"; char *t1 = NULL; char dest[1000] = {0}; int srcindex = 0;// index of src int destindex = 0;// index of dest int length = strlen(src); char temp; while(srcindex < length){ switch(src[srcindex]){ case 'B': CHANGE(Beta) break; case 'G': CHANGE(Gamma) break; case 'D': CHANGE(Delta) break; case 'E': CHANGE(Epsilon) break; case 'A': CHANGE(Alpha) break; default: dest[destindex] = src[srcindex]; destindex++; srcindex++; } } dest[destindex] = '/0'; printf("The dest is : %s/n" ,dest); system("pause"); }