C language programming> twenty-first week① In the following given program, the function of the function fun is to compare two character strings and return the first address of the long character string as the function value.

Example: In the following given program, the function of the function fun is to compare two character strings and return the first address of the long character string as the function value.

例如,输入 两串字符分别为“asdf”和"asdfg",则输出为 “asdfg”。
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构。

代码如下:

#include<conio.h>
#include<stdio.h>
char*fun(char*s,char*t)
{
    
    
	int s1=0,t1=0;
	char*str1,*str2;
	str1=s;
	str2=t;
	while(*str1)
	{
    
    
		s1++;
		str1++;
	}
	while(*str2)
	{
    
    
		t1++;
		str2++;
	}
	if(t1>s1)
		return t;
	else
		return s;
}
main()
{
    
    
	char p[80],q[80];
	printf("\nEnter a string: ");
	gets(p);
	printf("\nEnter another string:");
	gets(q);
	printf("\nThe longer is:%s\n",fun(p,q));
}

The output running window is as follows:
Insert picture description here

越努力越幸运!
加油,奥力给!!!

Guess you like

Origin blog.csdn.net/qq_45385706/article/details/112800051