1

I am writing code to emulate the strcat function in the c library and I can't pass my first test in main. I was wondering if someone could guide me as to why. here is my code:

#include <stdio.h>

char *strcat(char string1[ ], char string2[ ])
{
    int i;
    int j;


    for(i = 0; string1[i] != '\0'; i++);

    for(j=0;string2[j] != '\0';j++)
    {

        string1[i] = string2[j];
        i++;


    }

    string1[i] = '\0';
}



int main() { 
    char str1[81], str2[81]; 
    char again = 'y', newline; 
    while (again == 'y') { 
        printf("Enter a string\n"); 
        scanf("%s", str1); 
        printf("Enter another string\n"); 
        scanf("%s", str2); 
        printf("The concatention is %s\n", strcat(str1, str2)); 
        printf("Second test:  The concatenation is %s\n", str1);
        printf("The second string is still %s\n", str2); 
        printf("Again? (y/n)\n"); 
        scanf("%c%c", &newline, &again); 
    }
}
2

1 Answer 1

1

You must return the string1 is strcat.

return string1;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.