program6_09.c
来自「C语言入门经典一书的所有代码。书上面的所有代码均在此。希望大家喜欢」· C语言 代码 · 共 33 行
C
33 行
/* Program 6.9 Finding occurrences of one string in another */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(void)
{
char text[100]; /* Input buffer for string to be searched */
char substring[40]; /* Input buffer for string sought */
printf("\nEnter the string to be searched(less than 100 characters):\n");
fgets(text, sizeof(text), stdin);
printf("\nEnter the string sought (less than 40 characters ):\n");
fgets(substring, sizeof(substring), stdin);
/* overwrite the newline character in each string */
text[strlen(text)-1] = '\0';
substring[strlen(substring)-1] = '\0';
printf("\nFirst string entered:\n%s\n", text);
printf("\nSecond string entered:\n%s\n", substring);
/* Convert both strings to uppercase. */
for(int i = 0 ; (text[i] = toupper(text[i])) ; i++);
for(int i = 0 ; (substring[i] = toupper(substring[i])) ; i++);
printf("\nThe second string %s found in the first.",
((strstr(text, substring) == NULL) ? "was not" : "was"));
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?