string.h中常用6个函数(strcat、strcpy、strcmp、strlen、strlwr、strupr),自己选三个编程完成其中的功能。
时间: 2023-12-14 11:03:44 浏览: 30
好的,我知道了。这里是三个函数的示例代码:
1. strcat函数的示例代码:
```c
#include <stdio.h>
#include <string.h>
int main () {
char str1[100] = "Hello ";
char str2[]= "world";
strcat(str1, str2);
printf("%s", str1);
return 0;
}
```
输出结果为:Hello world
2. strcmp函数的示例代码:
```c
#include <stdio.h>
#include <string.h>
int main () {
char str1[100] = "Hello";
char str2[100] = "Hello";
int result = strcmp(str1, str2);
if (result == 0) {
printf("Strings are the same\n");
} else {
printf("Strings are different\n");
}
return 0;
}
```
输出结果为:Strings are the same
3. strlen函数的示例代码:
```c
#include <stdio.h>
#include <string.h>
int main () {
char str[100] = "Hello";
int length = strlen(str);
printf("The length of the string is %d\n", length);
return 0;
}
```
输出结果为:The length of the string is 5
希望这些示例代码可以帮助你完成任务。