12345678910111213141516171819202122232425262728293031323334 |
- /* strcat: concatenate t to end of s */
- #include <stdio.h>
- void strcat(char s[], char t[]);
- int main()
- {
- char lol1[100] = "aaaa";
- char lol2[100] = "xxxx";
- printf("string 1 : %s \n",lol1);
- printf("string 2 : %s \n",lol2);
- strcat(lol1,lol2);
- printf("string 1 : %s \n",lol1);
- printf("string 2 : %s \n",lol2);
-
- return 0;
- }
- /* write a pointer version of the function strcat that we showed in Chapter 2:
- strcat(s,t) copies the string t to the end of s. */
- void strcat(char s[], char t[])
- {
- // seek to end of s
- char* sp=s;
- while (*(sp++));
- sp--;
- do
- {
- (*sp)=(*t);
- sp++;
- }
- while (*(t++));
- }
|