+ 1

Why does this give no output (in new to c and c++)

Code : https://code.sololearn.com/ct06gCh9y26J/?ref=app

31st Jan 2017, 6:01 PM
zorionTheTenth
zorionTheTenth - avatar
6 Respostas
+ 2
printf("%d. %s",i,i); the '%d' expect an int and you give it at parameter, but '%s' expect a string and you give it the same integer: either the mistake is in this second parameter type, either it's in the format parameter in the 'placeholder' ( pre-formatted ) string... As you don't have any string variable declaration in your code, try to change by: printf("%d. %d",i,i);
31st Jan 2017, 6:27 PM
visph
visph - avatar
+ 2
Yes, it should work too ;)
31st Jan 2017, 6:30 PM
visph
visph - avatar
+ 2
Yep :P You'll try to convert an integer between 0 and 128 to a single char: it couldn't work ^^ With %d ant the int it work... if you like to convert the second int to a char, try that: printf("%d. %c",i,(char)(i+65)); You must change %s in %c, and add some count to your int, so the range isn't arround 0 ( first ascii char are non printable commands )...
31st Jan 2017, 6:44 PM
visph
visph - avatar
+ 2
Changing %s to %c did it. It works now thanks...
31st Jan 2017, 6:47 PM
zorionTheTenth
zorionTheTenth - avatar
+ 1
How about if I type cast the second integer to char.. It should print the char right?
31st Jan 2017, 6:29 PM
zorionTheTenth
zorionTheTenth - avatar
+ 1
Did it.. Still no output... I'm not even sure if my program is faulty or just Sololearn is messing something up... It just says "no output"
31st Jan 2017, 6:33 PM
zorionTheTenth
zorionTheTenth - avatar