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