0

I try to create a function, which returns astring (char array);

I tried different ways, but I always got error like:

[Error] conflicting types for 'readCommand'

Code:

char* cmd; //char cmd[256] *cmd = readCommand(); //function char* readCommand() { char cmd[256]; fgets(cmd, sizeof(cmd), stdin); return cmd; } 

How can I return a string from this function?

3
  • 1
    If cmd is not declared with the static qualifier, trying to access the returned value from readCommand will be undefined behavior Commented Dec 12, 2018 at 16:32
  • @GovindParmar i tried 'static char cmd[256];' bu the result the same. What I did wrong? Thank you! Commented Dec 12, 2018 at 16:34
  • @LeonidZolotarov The error comes from *cmd = readCommand(); instead of cmd = readCommand();, but you're doing it wrong anyway, read the duplicates. Commented Dec 12, 2018 at 16:38

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.