+ 1
What is the 4th case of symbols in code coach
I have written a code for symbols in code coach challenge but it was working for all the cases except 4th case please help me here is my code https://code.sololearn.com/c4D4DI1C4Dtz/?ref=app
4 ответов
+ 3
You can solve this with just 1 loop in 1 iteration, going over the input strings chars. No need for a nested for loop.
Get the input string loop over each char in the string and compare it to see if it is a-z, A-Z, 0-9, or ' '. If so, then you can output the char directly and go to the next iteration, or add the char to another string (char array) then output the whole string after the loop.
You can use the fact that a chars underlying type is an int to your advantage along with an if statement to see what to do with the char. You don't need another array of all the possible chars.
if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == ' ') {
... output char or add to char array
}
This code in your for loop will do the work of most of your code you have comparing to each possible char.
+ 3
PILLA CHANDRA SEKHAR Test 4 in your code is failing because the test input is greater than 49 characters.
You could also simplify your code by testing for acceptable characters and printing them in a single loop as suggested by ChaoticDawg
for (int i = 0; in[i] != '\0'; ++i) {
if ((in[i] >= 'a' && in[i] <= 'z') ||
(in[i] >= 'A' && in[i] <= 'Z') ||
(in[i] >= '0' && in[i] <= '9') ||
in[i] == ' ' )
{
printf("%c", in[i]);
}
}
+ 1
Thanks for all sir i gained lot of information
0
Is impossible to know the input, unless someone has a lot of time lol