+ 2

Whats wrong in my program . it says one test case failed which is hidden

It says one test case failed I am unable to figure out here is the code. #include <stdio.h> int main() { char str1[30],str2[30]; int first,last,i=0; gets(str1); while (str1[i]!='\0') i++; last=i-1; for(first=0;first<i;first++){ str2 [first]= str1 [last]; last--; } str2 [first ]='\0'; printf ("%s\n",str2 ); return 0; }

24th May 2020, 11:29 AM
Ritik Tiwari
Ritik Tiwari - avatar
10 Respuestas
+ 4
BTW, you can use strlen() to get the length of a C string. Also, you can solve this without the use of a second array. Try looping through the char[] backwards outputting the chars. https://www.programiz.com/c-programming/library-function/string.h/strlen
24th May 2020, 12:08 PM
ChaoticDawg
ChaoticDawg - avatar
+ 4
strrev depends on which compiler you're using and is non standard. Here are a couple of common implementations. https://www.sololearn.com/Discuss/1350351/?ref=app
24th May 2020, 12:19 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
You'll need to show your code. We can't view your attempts, so, you'll need to copy your code to the playground, save it, then post a link to it.
24th May 2020, 11:35 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Increase your char[] length to 35.
24th May 2020, 11:52 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Yes its solved TQ ChaoticDawg i should have cared about string length
24th May 2020, 11:54 AM
Ritik Tiwari
Ritik Tiwari - avatar
+ 3
ChaoticDawg oh that was the reason . TQ for clearing my doubts
24th May 2020, 12:24 PM
Ritik Tiwari
Ritik Tiwari - avatar
+ 3
i don't find any mistake in your code. Please try to use NULL instead of \0 in this case.
24th May 2020, 5:42 PM
Win Htay 🇲🇲
Win Htay 🇲🇲 - avatar
+ 3
Your code is correct i tried in compiler i have not found any mistakes . Try other plateform
26th May 2020, 5:12 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
ChaoticDawg I tried using strrev it was giving error so I thought strlen would not work. May be restricted in code couch problem. That's why I didn't use.
24th May 2020, 12:11 PM
Ritik Tiwari
Ritik Tiwari - avatar