#include #include //#include //every string in C read scanf("%s") gets() end with '\0' char temp[20]; int length(char w[])//srtlen { int i; i=0; while(w[i]!='\0') { i++; } return i; } //from=panos,to=koligas char* string_copy(char *from,char *to)//strcpy { int i=0,j=0; printf("\nentering string_copy:i=%d,j=%d",i,j); if(length(to)>length(from))//αν το μήκος του to einai megalytero apo to mikos toy from { printf("\nto=%d---from=%d",length(to),length(from));//ektypwsi twn mikwn to,from... getchar(); printf("\nbegin copy from to temp..."); //copy olo to from sto temp for(i=0,j=0;from[j]!='\0';i++,j++) { temp[i]=from[j]; printf("\n1.%d=%c",i,from[j]); getchar(); } printf("\nafter copying from to temp...temp=%s",temp);//ektypwsi temp mexri stigmis getchar(); //i--; for(j=length(from);to[j]!='\0';j++)//antigrafi twn ypoloipwn xaraktirwn toy sto temp { temp[i++]=to[j]; } temp[i]='\0'; printf("\nafter copying the rest of to temp=%s",temp);//printing again temp getchar(); i=0; j=0; printf("\n2"); getchar(); } return temp; } void string_concat(char *to,char *from)//strcat { int i=0; while(to[i++]!='\0') ;; int j=0; i--; while(to[i++]=from[j++]) ;; } int main() { char w[20]; printf("give a word up to 20 characters: "); gets(w); printf("\nyou gave: %s\nit contains: %d characters!!",w,length(w)); getchar(); system("cls"); char w1[20]; char *w2="koligas"; printf("give a word up to 20 characters: "); gets(w1);//w1=panos w2=string_copy(w1,w2);//from=w1=panos,to=w2=koligas printf("\nmain---after copying: %s",w2);//w1="panos",w2="panosas"; getchar(); system("cls"); if(length(w)+length(w2)<20) { string_concat(w,w2); printf("after concatanating: %s",w); getchar(); system("cls"); } return 0; }