- 1

How to Convert number into corresponding word in string?

Please don't laugh with my code 😅 https://code.sololearn.com/cwQL9oKMFcEd/?ref=app

27th Nov 2020, 1:58 AM
Bibek Pant
Bibek Pant - avatar
3 Respostas
+ 3
For the case of 1 and ten case '1': { if (str[i + 1] == '0') { strcat(output, "ten"); ++i; break; } else { strcat(output, "one"); break; } } And considering the length of string for numbers, it may be considered that the input is limited to maybe 10 ~ 15 characters.
27th Nov 2020, 6:23 AM
Ipang
+ 1
Is this about the No Numeral challenge? if it is, then here are some points to ponder * When you iterate through a C-string, you are working with characters, so in the switch cases, you must also compare against char. case '0': // do something * You can't replace a char by a string, so doing the below lines is not quite right. And a string is represented with double quotes, not single quotes. case 0: str[i] = 'zero'; I suggest you to prepare a char array as output buffer. The buffer should be large enough to hold the strings and spaces (if necessary). Then learn to put strings into the buffer using http://www.cplusplus.com/reference/cstring/strcat/ I'm not laughing at your code. I don't laugh at one's honest work. I laugh at one who doesn't want to give a try, and want a quick solution. Besides, everyone must've been through the early days of coding, so what?
27th Nov 2020, 2:44 AM
Ipang
+ 1
Ipang , I am still not able do it. Would you mind checking my new code please? https://code.sololearn.com/c5jFG20G1CA4/?ref=app
27th Nov 2020, 5:52 AM
Bibek Pant
Bibek Pant - avatar