Home > Back-end >  Find the specified character
Find the specified character

Time:01-27

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)

CodePudding user response:

refer to the second floor CHXCHXKKK 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)

I tried as you said, only to have a test point is wrong

CodePudding user response:

Reference:
 # include "stdio.h" 
# include "string. H"
Int main ()
{
Char s [1], c, a, [81].
Int flag=1, I;
The scanf (" % s ", s);//the scanf (" % c \ n ", & amp; C);
C=s [0];
//gets (a);
scanf("%s",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==1)
Printf (" Not Found ");
The else
Printf (" index=% d ", flag);

return 0;

CodePudding user response:

The
reference 4 floor QZJHJXJ reply:
for reference:
 # include "stdio.h" 
# include "string. H"
Int main ()
{
Char s [1], c, a, [81].
Int flag=1, I;
The scanf (" % s ", s);//the scanf (" % c \ n ", & amp; C);
C=s [0];
//gets (a);
scanf("%s",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==1)
Printf (" Not Found ");
The else
Printf (" index=% d ", flag);

return 0;

I tried your code, or you don't have a test point

CodePudding user response:

reference room response: 1/f, the cloud
I mentioned no repetition to the building inside comments here, is the specific problems on how to operate the

Just knock on the compiler, is no problem, but I can't through test system has a test point

CodePudding user response:

Title say non-empty string, didn't say that in the string does not contain Spaces,
  • Related