this is what is wrong? Subject to code program, from a given search for a specified character string,
Input format: The first line of the input is a character, to find the second line is a non-empty string ends with a carriage return (not more than 80 characters),
The output format: If found, in a line according to the output format "index=subscript" the character in the string that corresponds to the largest subscript (subscript starting from 0); Otherwise output "Not Found",
Input the sample 1: M Programming The output sample 1: The index=7 Enter the sample 2: A 1234 The output sample 2: Not Found
# include "stdio.h" # include "string. H" Int main () { Char c, a, [100]. Int flag=100, I; The scanf (" % c \ n ", & amp; C); Gets (a);//the scanf (" % s ", & amp; A); Why to % s is wrong? Wrong a test point For (I=0; I & lt; Strlen (a); I++) If (c==a [I]) Flag=I; If (flag==100) Printf (" Not Found "); The else Printf (" index=% d ", flag);
return 0; }
CodePudding user response:
I mentioned repetition here is not to the original poster inside comments, specific problems on how to operate
CodePudding user response:
The scanf (" % c \ n ", & amp; C); Remove the here \ n, Gets (a);//the scanf (" % s ", & amp; A); Why to % s is wrong? Wrong a test point in the scanf (" % s ", & amp; A) when, can't add & amp; The scanf (" % s ", a)