I am having trouble with my Int2String method. I am new to C so I am not sure if this would be the correct way to go about it. I’m receiving a few error messages:
error: conflicting types for ‘int2String’
warning: return makes integer from pointer without a cast
Here is my method:
char int2String(int num, char intStr[10]) {
char itoa(num, intStr[10]);
return itoa;
}
Thanks for any help!
In your code
tells the compiler that you declare a function called
itoawith specific signature, then you want to return (a pointer to) this function. Since you declared the return type aschar, the compiler doesn’t like this.It should rather look something like
i.e. call the function
itoawith given parameters, store its return value in a local variable of typechar, then return it. (The local variable could be inlined to simplify the code.)Now this still does not make the compiler happy, since
itoa, although not part of the standard, is by convention declared to returnchar*, and to take 3 parameters, not 2. (Unless you use a nonstandard definition ifitoa, that is.)With the “standard”
itoaversion, this modification should work (in theory at least – I have not tested it 🙂