0

Why Coach Section is not working?

Coach section is not working because the below program's output is correct same as expected output but it not accepting. I also have screenShot but unable to attach it. The problem is of Extra-Terestials The program print the reverse order of string. #include <stdio.h> #include<stdlib.h> int main() { char letter[50]=""; int i; scanf("%s",letter); for(i=49; i>=0; i--) { printf("%c",letter[i]); } return 0; }

23rd Dec 2019, 3:11 PM
PRINCE KUMAR
12 ответов
+ 4
PRINCE KUMAR , a string is defined as a character array and a '\0'(NULL) character at the end The think which you are doing is that you are displaying just characters not a string. As your program is reading NULL character first
23rd Dec 2019, 3:25 PM
Arsenic
Arsenic - avatar
+ 3
PRINCE KUMAR , this is a very obvious mistake that people make.🙂🙃 The problem is that you are displaying characters, not string as a whole
23rd Dec 2019, 3:16 PM
Arsenic
Arsenic - avatar
+ 3
Problem solved 👌 using two for loops it get solved
23rd Dec 2019, 5:15 PM
PRINCE KUMAR
+ 1
Arsenic No because it is printing whole string in output
23rd Dec 2019, 3:18 PM
PRINCE KUMAR
+ 1
I have never listened to 'a string' or 'several strings' or whatever and have always just scanf'ed what seemed to work best, single string, several strings, bunch of letters... output the same. And that was never the problem. Problem is rather that you arbitrarily start from 49 (where there would be a 0 anyway), although they might have given a shorter string.
23rd Dec 2019, 4:13 PM
HonFu
HonFu - avatar
+ 1
HonFu, do we not have in C a nice function like len() in python?
23rd Dec 2019, 4:40 PM
Coding Cat
Coding Cat - avatar
+ 1
Yeah, you can use strlen from string.h. Funny, didn't think of it. 😂 Basically, if you have an int i=0 flying around, all you have to do would be something like: while(str[i++]);
23rd Dec 2019, 5:02 PM
HonFu
HonFu - avatar
0
I think my Python solution works also charakter for character. But only with the given input. Not 50 or some what else. Hint: If you set i=6 or i=7 in your loop, then it will pass test case 1 or test case 2.
23rd Dec 2019, 3:41 PM
Coding Cat
Coding Cat - avatar
0
Start with 0 is not possible. He did it backwards. He need the lenght of the word as start. But then it must work. Could it only test for i=6 and i=7.
23rd Dec 2019, 4:23 PM
Coding Cat
Coding Cat - avatar
0
any particular solution for it
23rd Dec 2019, 4:24 PM
PRINCE KUMAR
0
HonFu I want to print reverse string. How can it start from 0
23rd Dec 2019, 4:26 PM
PRINCE KUMAR
0
Make an int and run it up until you find the last letter '\0'. Start one point lower, then read the string backwards.
23rd Dec 2019, 4:36 PM
HonFu
HonFu - avatar