The Spy Life in C | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The Spy Life in C

■□■FIXED■□■ Thank youuu♡ /* For some reason my code doesn't pass the 3 and 5 test, Any idea why is that? Thanks */ #include <stdio.h> #include <string.h> #include <ctype.h> int main() { char* s =NULL; size_t size = 0; getline(&s,&size,stdin); size_t len = strlen(s); char a[len+1]; int j = 0; for(int i=len; s[len-i]!= '\0';i--) { char c=s[i-1]; if(isalpha(c) || isspace(c)) { a[j]= c; j++; } } a[j] = '\0'; printf("%s",a); return 0; }

5th Jul 2020, 6:11 PM
Roby
Roby - avatar
3 Answers
+ 1
It doesn't work because I have to get rid of \n and \0 I think
5th Jul 2020, 7:30 PM
Roby
Roby - avatar
0
#include <iostream> using namespace std; int main() { string abc = "abcdefghijklmnopqrstuvwxyz ",s = "6s1o2c3a4t5",rs; bool k = 1; getline(cin, s); for (int j=s.size()-1;j>=0;j--){ if(isupper(s[j])){ s[j]=tolower(s[j]); k=0; } for (long unsigned int i=0;i<abc.size();i++) { if (abc[i]==s[j]){ if(k==0){ s[j]=toupper(s[j]); } rs = rs+s[j]; k=1; break; } } } cout<<rs; return 0; } This is in c++ , you can remake to C )
5th Jul 2020, 7:02 PM
꧁༒☬Bad☬Boy☬༒꧂
꧁༒☬Bad☬Boy☬༒꧂ - avatar
0
Roby Just do 2 change s[len - (i + 2)] to s[len - (i + 1)] and a[len + 1] to a[len]
5th Jul 2020, 7:16 PM
A͢J
A͢J - avatar