Return error as string in C #125205
Answered
by
davevad93
typetypetype2
asked this question in
Programming Help
-
Body
In this code, 6 should be output, but it outputs (null) Guidelines
|
Beta Was this translation helpful? Give feedback.
Answered by
davevad93
May 22, 2024
Replies: 1 comment 1 reply
-
Hi @typetypetype2 , I'm not a #include <stdio.h>
char* def(int num)
{
static char result[2];
if(num<10 && num!=1)
{
result[0] = num+48;
result[1] = '\0';
return result;
}
return NULL;
}
int main()
{
printf("%s\n", def(6));
return 0;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
typetypetype2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @typetypetype2 ,
I'm not a
C
expert but i think it's because of how thedef
function is returning the result, try with this it should work: