C语言初学数组的一道题。

C语言初学数组的一道题。请大神编写代码。
2025-03-07 09:31:43
推荐回答(1个)
回答1:

//#include "stdafx.h"//If the vc++6.0, with this line.
#include 
#include "string.h"
int main(int argc,char *argv[]){
    char str1[256],str2[256];
    int l1,l2;
    printf("Input 2 strings...\n");
    scanf("%s%s",str1,str2);
    if((l1=strlen(str1))>(l2=strlen(str2)))
        printf("%s\n",strncpy(str1,str2,l2));
    else if(l1        printf("%s\n",strncpy(str2,str1,l1));
    else
        printf("error\n");
    return 0;
}