0

What's wrong with the code? (solution to The Spy Life) Show several errors. But It runs just fine in other compilers!

#include <stdio.h> #include <string.h> char rev(int len, char *str) { int i, j; i = len -1; j=0; char ch; while(i>j) { ch = str[i]; str[i] = str[j]; str[j] = ch; i--; j++; } } char rmv(int len, char *str) { int i; for(i=0;i<len;i++) { if((str[i]>=65 && str[i]<=90) || (str[i]>=97 && str[i]<=122) || str[i] == 32) { printf("%c", str[i]); } } } int main() { char code[100]; int l; gets(code); l=strlen(code); rev(l, code); rmv(code); return 0; }

30th May 2020, 2:37 PM
Syfur Rahman
Syfur Rahman - avatar
11 Answers
+ 4
You probably get a warning for using gets() which you should not be using anyway. Change gets() to fgets(code, sizeof(code), stdin); rmv() takes an int len argument, but you pass in only the string. Change it to rmv(l, code); As a stylistic choice, I would probably swap printf("%c", str[i]) for putchar(str[i]) and declare char *str as const in the rmv() function.
30th May 2020, 3:30 PM
Gen2oo
Gen2oo - avatar
+ 3
In your program have too much errors don't use gets in program in main where u write rmv u passed few parameters first try to fix the bug then try in test case
1st Jun 2020, 11:28 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
What kind of error?
30th May 2020, 3:13 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 2
Okkk so you have tried to make a code for reversing a string!!!!! I've tried your code. You have made some mistakes. Let me clarify you!!!! 1) you have used "gets" function in your code which doesn't work in this app . You have to use "fgets" instead of "gets" function. 2) you have passed only a single string argument in rmv function while rmv function takes two arguments first is integer and second one is a string. 3) you have declared rev and rmv functions as "non-void" type i.e. char type which are expected to return a char type value but in last you have returned nothing like in a void function. So you have declared rev and rmv functions as "void" type. I've corrected your code. Hope!!! It helps. https://code.sololearn.com/cLFEK3jLtS7e/?ref=app
31st May 2020, 10:53 AM
Amaan Khan
Amaan Khan - avatar
+ 1
Please save this as a code and provide a link so that people can test it.
30th May 2020, 2:44 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
Worked like a charm, thanks for the 10xp bonus ;)
30th May 2020, 3:10 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
Old what is the answer for module 2 quiz in html
1st Jun 2020, 10:51 AM
Charis
Charis - avatar
+ 1
About which question number you are talking about??? If third question then answer is <tr>
1st Jun 2020, 11:03 AM
Amaan Khan
Amaan Khan - avatar
0
The code works in codeplayground. But shows error in the code coach compiler.
30th May 2020, 3:00 PM
Syfur Rahman
Syfur Rahman - avatar
0
Mean please
1st Jun 2020, 10:51 AM
Charis
Charis - avatar
- 1
Not working for me :|
30th May 2020, 3:12 PM
Syfur Rahman
Syfur Rahman - avatar