jun-csbio / CClass_ZJUT

CClass_ZJUT
1 stars 0 forks source link

字符型数组头接屁股: #39

Open sq4250 opened 1 year ago

sq4250 commented 1 year ago
#include <stdio.h>
int main()
{
    char str1[100], str2[100];
    int i = 0;
    scanf("%s%s", str1, str2);
    while (str1[i] != '\0')
        i++;
    for (int ii = 0; str2[ii] != '\0'; ii++)
    {
        str1[i + ii] = str2[ii];
    }
    printf("%s\n", str1);
    return 0;
}

or:

#include <stdio.h>
#include <string.h>
int main()
{
    char str1[100], str2[100];
    scanf("%s%s", str1, str2);
    strcpy(&str1[strlen(str1)], str2);
    printf("%s\n", str1);
    return 0;
}