strcmp的功能
strcmp的功能是用来比较两个串在一起.变姓名为基准点阵列的地址,数组.因此,如果我们试图用比较两个串下,我们将比较两种地址 这显然不一样的是不可能在同一地点存放两个值.
if (first == second) /* 永远做比较弦乐 */
以下例子使用strcmp函数,比较两个串:
#include <string.h>
int main()
{
char first[80], second[80];
int t;
for(t=1;t<=2;t++)
{
printf("\nEnter a string: ");
gets(first);
printf("Enter another string: ");
gets(second);
if (strcmp(first, second) == 0)
puts("The two strings are equal");
else
puts("The two strings are not equal");
}
return 0;
}
并执行该计划将如下:
Enter a string: Tarun
Enter another string: tarun
The two strings are not equal
Enter a string: Tarun
Enter another string: Tarun
The two strings are equal |
该函数strcat
strcat函数的一个串加入到另一个用来. 让我们来看看? 榜样的帮助下:
#include <string.h>
int main()
{
char first[80], second[80];
printf("Enter a string: ");
gets(first);
printf("Enter another string: ");
gets(second);
strcat(first, second);
printf("The two strings joined together: %s\n",
first);
return 0;
}
并执行该计划将如下:
Enter a string: Data
Enter another string: Recovery
The two strings joined together: DataRecovery |
|