hey guys,
i am trying to write a function where i convert a string of numbers to their ASCII-equals
i know that a function can only have 1 return value which is why i want/need to have a pointer as a return value to return the whole string.
i know that i need a pointer but i have no clue how to write the function.
Code:
int *stoi(char str[]) {
int z;
int g = 0;
for (z = 0; str[z] != '\0'; z++) {
g = ctoi(str[z]);
str[z] = g;
}
return str;
}
this is the ctoi function:
int ctoi(char c) {
int i = 0;
i = c - '0';
return i;
}
this is the code i have for the function.
i want to call the function like this:
char *str = "-211";
int *x;
x = stoi(str);
printf("\n%i \n", *x);
return EXIT_SUCCESS;
and as you see i want to output the string into the console, but it just stays empty.
i am using eclipse-c++ on ubuntu linux
Quote from: scy on November 04, 2015, 03:05:17 PM
i am using eclipse-c++ on ubuntu linux
Well, this forum is for Pelle's C, which only runs on Windows ;-)
And we usually don't do the homework for other either.
I am a bit short on time right now (just stopped by to check for spammers to zap), I will get back to you with some hints later if no one else is biting in the meantime ... ;)
Ralf