Hey guy's. Can't get this seemingly simple function to work. It is suppost to get a string and return the first 10 characters, than the next time you call it, it returns the second 10 cheracters and so on. I did this in basic a while ago without problems, C seems more stubborn.
char *extract(int *pos, char *array) {
/* This function extracts 10 didget's at a time from 'array'. */
char output[11] = {0};
int max = (*pos) + 10, count = 0;
while(*pos != max) {
output[count] = array[*pos];
count++;
(*pos)++;
}
return *output;
}
And I called it with:
int pos = 0;
char *string = "BlahBlahBlahBlahBlahBlah......";
extract(&pos, string);
extract(&pos, string);
It exits with a segment fault. Thanks for any input.