Skip to content

Return error as string in C #125205

Discussion options

You must be logged in to vote

Hi @typetypetype2 ,

I'm not a C expert but i think it's because of how the def function is returning the result, try with this it should work:

#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;
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@typetypetype2
Comment options

Answer selected by typetypetype2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Programming Help Programming languages, open source, and software development.
2 participants