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?
cmdis not declared with thestaticqualifier, trying to access the returned value fromreadCommandwill be undefined behavior*cmd = readCommand();instead ofcmd = readCommand();, but you're doing it wrong anyway, read the duplicates.