+ 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; }
10 Réponses
+ 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
+ 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
+ 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.
+ 3
Increase your char[] length to 35.
+ 3
Yes its solved TQ ChaoticDawg i should have cared about string length
+ 3
ChaoticDawg oh that was the reason . TQ for clearing my doubts
+ 3
i don't find any mistake in your code. Please try to use NULL instead of \0 in this case.
+ 3
Your code is correct i tried in compiler i have not found any mistakes . Try other plateform
+ 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.