user12187654
user12187654

Reputation:

character Function in C does not output anything

I am a beginner in C and im currently learning how to make functions in C, below is my code where i want a user to input a name and an occupation at random, then the users random input will be replaced in a sentence. The problem is that when i run this particular program there is no output at all, I am using CodeBlocks and its a console application but when i build and compile and run it, there is nothing on the screen as you can see below, as well as this there is no error messages at all in the "Build log" section where you can normally see errors, the program runs but outputs nothing.

When the program is run all i see on the console is

"Process returned 0 (0x0) execution time : 0.016 s Press ENTER to continue."

#include <stdio.h>
#include <stdlib.h>

char FunOne(char Wun[50], char Two[50]);

int main()
{
    char FunOne(char Wun[50], char Two[50]);
    return 0;
}

char FunOne(char Wun[50], char Two[50])
{
    printf("please enter a name: ");
    fgets(Wun, 50, stdin);
    printf("please enter a occupation: ");
    fgets(Two, 50, stdin);
    printf("there was once a man named %s", Wun);
    printf("he lived in the UK and worked as a %s", Two);

    return 0;
}

Upvotes: 2

Views: 96

Answers (1)

anastaciu
anastaciu

Reputation: 23832

The problem is in your main() function, you should do something like this:

Running sample

char FunOne(char Wun[50], char Two[50]); //declaration

int main()
{
    char Wun[50], Two[50]; //declaration of variables (char arrays in this case)
    FunOne(Wun, Two);  //usage
    return 0;
}


char FunOne(char Wun[50], char Two[50]) //definition
{
    //...
}

Upvotes: 2

Related Questions