0

I am trying to have one function pass an string into a string like this:

char taBortTecken(char inputString[]){

//antalBokstaver-1 make sure the string is just the right size. This is working properly
char nyString[antalBokstaver-1];

return nyString;

}

int main(void){
char inputString[] = "halloj i stugan";

char hellA[] = taBortTecken(inputString);


return 0;
}

Basically main is calling Stringfuction and giving it a string, it does its work and passes back a "processed" string (not the same content obviously). Note that this code in not working but sums up what I am trying to do.

6
  • 1
    In order to make more clear what your environment is, you should give at least the declaration and definition of inputString. Commented Feb 1, 2018 at 14:30
  • I think you want something which will require the function to know the size of the buffer/array which contains the string, especially if the processing can increase the string length. Commented Feb 1, 2018 at 14:33
  • Note that strings are null-terminated arrays in C, and you can't return arrays from functions. Your options are: 1) pass SuperString[] into the function and modify it there; 2) dynamically allocate within the function and return a pointer to the allocation; 3) wrap SuperString[] in a struct and return the struct. Commented Feb 1, 2018 at 14:34
  • 1
    Possible duplciate: stackoverflow.com/questions/25798977/… Commented Feb 1, 2018 at 14:34
  • I am not allowed to use option 2 and 3... How do you mean by option 1? Commented Feb 1, 2018 at 14:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.