0
I have a problem with converting an integer to string in the scope of a function where the conversion return is given as null and I don’t know why.
#include <stdio.h>
char *getTexto(int num) {
char numTxt[7];
itoa(num, numTxt, 10);
if ( num % 3 == 0 ) {
if ( num % 5 == 0 ) {
return "TicTac";
}
else {
return "Tic";
}
}
else if ( num % 5 == 0 ) {
return "Tac";
}
else {
return numTxt;
}
}
int main() {
for ( int x = 1; x <= 100; x++ ) {
printf("\n%s", getTexto(x));
}
return 0;
}
Good morning @Noronha, welcome, see if this helps you https://answall.com/questions/436759/como-converter-string-para-int-em-c/436760#436760
– Thiago Costa
vc can simplify by removing the last
else
and leave thereturn numTxt
– Ricardo Pontual