+ 2

Spy life

Hi all, i have written below code and it is not sussed, I got error with all tests. Can you help me to understand why? #include <stdio.h> #include <string.h> int main() { char line[150]; fgets(line, sizeof(line), stdin); for (int i = 0, j; line[i] != '\0'; ++i) { while (!(line[i] >= 'a' && line[i] <= 'z') && !(line[i] >= 'A' && line[i] <= 'Z') && !(line[i] == ' ') &&!(line[i] == '\0')&&!(line[i] == '\n')) { for (j = i; line[j] != '\0'; ++j) { line[j] = line[j + 1]; } line[j] = '\0'; } } for (int i = strlen(line); i >= 0; --i){ printf ("%c", line[i]); }

5th Nov 2021, 8:59 AM
ElkanaM
ElkanaM - avatar
9 Respostas
0
i wrote the code another way and it worked yet i don't know why this one is not passing test cases so i cant really help out , i hope some one with better understanding can find out why
5th Nov 2021, 9:41 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 2
You just forgot to add } at the end :)
5th Nov 2021, 9:12 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 2
The } at the end is to close the for loop The main {} Is not closed
5th Nov 2021, 9:13 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
Can you copy the task content here?
5th Nov 2021, 9:32 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
+ 1
Thanks, the issue was on latest for loop: I just add -1 to initial i value. for (int i = strlen (line)-1; i >= 0 b --i)
5th Nov 2021, 10:30 AM
ElkanaM
ElkanaM - avatar
+ 1
Thx for sharing how it got fixed
5th Nov 2021, 10:37 AM
Dareen Moughrabi
Dareen Moughrabi - avatar
0
dareen moughrabi this is copy error, the code run and print the letters only on reverse. But it return error!
5th Nov 2021, 9:16 AM
ElkanaM
ElkanaM - avatar
0
Let say the input is "1o2l3l4e5H6" The output is "Hello" It work also with special letters.
5th Nov 2021, 9:21 AM
ElkanaM
ElkanaM - avatar
0
You are a secret agent, and you receive an encrypted message that needs to be decoded. The code that is being used flips the message backwards and inserts non-alphabetic characters in the message to make it hard to decipher. Task: Create a program that will take the encoded message, flip it around, remove any characters that are not a letter or a space, and output the hidden message. Input Format: A string of characters that represent the encoded message. Output Format: A string of character that represent the intended secret message. Sample Input: d89%l++5r19o7W *o=l645le9H Sample Output: Hello World
5th Nov 2021, 9:33 AM
ElkanaM
ElkanaM - avatar