0

(solved)Help me with string functioning in C. Thank you already🤗

I have this code, which gets a sentence as input and outputs the same sentence but with all the numbers>0 and <=10 written in their word formats. But for some reason, I'm not getting the correct input, but somehow relevant one. Please help me. Thank you https://code.sololearn.com/cwcGQYJI8g30/?ref=app Edit:upgraded code(only timeout problem): https://code.sololearn.com/cdgEw7Gol1Ie/?ref=app

12th Jun 2021, 11:53 AM
Rishi
Rishi - avatar
13 Answers
+ 2
Ipang finally got the answer. Passed all the test cases https://code.sololearn.com/c0L41kuZ1vI9/?ref=app
13th Jun 2021, 5:34 AM
Rishi
Rishi - avatar
+ 2
Rishi, Good job 👍
13th Jun 2021, 5:41 AM
Ipang
+ 1
you forgot the name of the strtok function in the increment section of the for loop. However, there are some other problems
12th Jun 2021, 1:23 PM
Ciro Pellegrino
Ciro Pellegrino - avatar
+ 1
Rishi, Is this about the "No numerals" code coach? I had to ask, cause I don't see 10 being replaced by "ten" in your code. What input is needed to test?
12th Jun 2021, 3:32 PM
Ipang
+ 1
Ipang yes exactly. 😲 Yes I forgot to include that. I'll add that. By the way, if you found a way to change 0 to "zero", please tell me
12th Jun 2021, 4:01 PM
Rishi
Rishi - avatar
+ 1
Rishi, I have tried it, but my code wouldn't pass the coach test cause I added some things I had in mind back then. But you can check it to get some idea. BTW my code prints output directly, while your code writes to a string buffer which is printed once work is done. https://code.sololearn.com/cd7q4byR9cD6/?ref=app
12th Jun 2021, 4:39 PM
Ipang
+ 1
Ipang but there's one minor problem, it should print 55 as 55 only but your code prints it as five five. That's why I abandoned my code which used character by character. The code coach said that your code didn't pass a test case which is hidden?
13th Jun 2021, 3:29 AM
Rishi
Rishi - avatar
0
Ciro Pellegrino after that, it works somehow relevant but not the exact answer. Just some minor errors. Run it and see now. Is my code worth working or I have to let it go? If it's worth, please help me. Thank you
12th Jun 2021, 3:16 PM
Rishi
Rishi - avatar
0
Ciro Pellegrino see my new code https://code.sololearn.com/cdgEw7Gol1Ie/?ref=app It works correctly but except for changing 0 to "zero". In the part I try to do that, I'm getting timeout error and I don't know why. Please help me. Thank you.
12th Jun 2021, 3:26 PM
Rishi
Rishi - avatar
0
/*I didn't realize it was a code coach exercise. I solved it like this*/ #include <stdio.h> int main() { char s[100]; while(scanf("%s",s)!=EOF){ if(s[0]=='0' && strlen(s)==1){ printf("zero "); continue; } switch(atoi(s)){ case 1:printf("one ");break; case 2:printf("two ");break; case 3:printf("three ");break; case 4:printf("four ");break; case 5:printf("five ");break; case 6:printf("six ");break; case 7:printf("seven ");break; case 8:printf("eight ");break; case 9:printf("nine ");break; case 10:printf("ten ");break; default: printf("%s ",s); } } return 0; }
13th Jun 2021, 6:44 AM
Ciro Pellegrino
Ciro Pellegrino - avatar
0
Ciro Pellegrino it's so simple😲, I just came to know that we can take string inputs like this too
13th Jun 2021, 8:38 AM
Rishi
Rishi - avatar
- 1
Wate
13th Jun 2021, 12:59 PM
Derek Lo
Derek Lo - avatar