Question: So, I'm trying to code a strcat function using pointers, just for studying purposes.

```
#include <stdio.h>
#include <string.h>

char *strcpyy(char *dest, char *orig){
    char *tmp = dest;
    while (*dest++ = *orig++);
    return tmp;
}

char *strcatt(char *dest, char *orig){
    strcpyy(dest + strlen(dest), orig);
    return dest;
}

int main(){
    char *a = "one";
    char *b = "two";
    printf("%s", strcatt(a,b));
}

```

When I run this code, the output is empty. Can anyone point out the problem?

Answer: 
[String literals](https://en.cppreference.com/w/c/language/string_literal) are read-only. Any attempt to write to a string literal will invoke [undefined behavior](https://en.wikipedia.org/wiki/Undefined_behavior), which means that your program may crash or not behave as intended.

Therefore, you should not use a pointer to a string literal as the first argument to `strcat` or your equivalent function. Instead, you must provide a pointer to an object which is writable and has sufficient space for the result (including the terminating null character), for example a `char` array of length `7`. This array can be initialized using a string literal.

Therefore, I recommend that you change the line

```
char *a = "one";

```

to the following:

```
char a[7] = "one";

```

After making this change, your program should work as intended.
You cannot modify "string literals". Those are not *mutable*.

The usual *idiom* for this sort of operation is to build up a string in a temporary *working buffer* that *should be* pre-dimensioned large enough to hold all that is required.

The following also shows more obvious code in both your functions.

```
#include <stdio.h>

char *strcpyy( char *dst, const char *org ) {
    for( char *p = dst; (*p++ = *org++) != '\0'; /**/ )
        ; // loop
    return dst;
}

char *strcatt( char *dst, const char *org ) {
    char *p = dst;
    while( *p != '\0' )
        p++; //loop
    while( (*p = *org++) != '\0' )
        p++; // loop
    return dst;
}

int main(){
    const char *a = "one ";
    const char *b = "two ";
    const char *c = "three";

    char wrk[ 64 ]; // sufficient mutable space defined

    printf( "%s\n", strcatt( strcatt( strcpyy( wrk, a ), b ), c ) );

    return 0;
}

```

```
one two three

```