PAT 10-1 find the specified character in the string, pat10-1
Baidu's practices of the other two are to judge whether a match is matched first, and then use a for () loop output. Of course, I also judge it first, and then directly puts (), the question setting requirements and code implementation are as follows:
/* Name: Copyright: Author: Date: 03/04/15 Description: enter a string S and a character c. Search for the character c in string S. If Not found, "Not found" is output. If Not found, all characters starting from c in string S are output. Input Format: enter a non-empty string of no more than 80 characters ending with a carriage return in line 1st, and a character in line 2nd. Output Format: output results in one row according to the requirements of the question. Input Example 1: It is a black boxb output Example 1: black box input Example 2: It is a black boxB output Example 2: not found */# include <stdio. h> # include <string. h> # include <stdbool. h> # define MAX 80 void print (char * S, int l, char c); int main () {// freopen ("in.txt", "r", stdin ); // for test char S [80], c; int l; gets (S); l = strlen (S); c = getchar (); print (S, l, c); // fclose (stdin); // for test return 0;} void print (char * S, int l, char c) {int I; for (I = 0; I <l; I ++) {if (S [I] = c) {puts (S + I); break ;}} if (I = l) printf ("Not found \ n ");}