use C program Enter a string s, and then enter a character c, find the character c in the string s. If it cannot be found, output "Not found"; If found, all characters in the string s starting from c will be output. [Input] In the first line, give a non empty string that is no longer than 80 characters and ends with enter; Give a character in the second line. [Output] Output the results in a row according to the requirements of the topic.
时间: 2024-02-28 11:57:50 浏览: 68
Sure, here's a C program that accomplishes the task you described:
```C
#include <stdio.h>
#include <string.h>
int main() {
char s[81], c;
int i, j, found = 0;
// Input the string
printf("Enter a string: ");
fgets(s, 81, stdin);
s[strcspn(s, "\n")] = '\0'; // remove the newline character
// Input the character
printf("Enter a character: ");
scanf("%c", &c);
// Search for the character in the string
for (i = 0; i < strlen(s); i++) {
if (s[i] == c) {
found = 1;
for (j = i; j < strlen(s); j++) {
printf("%c", s[j]);
}
break;
}
}
// Output the result
if (!found) {
printf("Not found");
}
printf("\n");
return 0;
}
```
You can compile and run this code to test it out.
阅读全文