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; }
11 Respostas
+ 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.
+ 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
+ 2
What kind of error?
+ 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
+ 1
Please save this as a code and provide a link so that people can test it.
+ 1
Worked like a charm, thanks for the 10xp bonus ;)
+ 1
Old what is the answer for module 2 quiz in html
+ 1
About which question number you are talking about???
If third question then answer is <tr>
0
The code works in codeplayground. But shows error in the code coach compiler.
0
Mean please
- 1
Not working for me :|