0
char stripper(char x[]){ char stripped[20]; int c=0; for(int i=0; i<strlen(x);i++){ if(x[i]==' '){ continue; } else{ stripped[c]=x[i]; c++; } } return stripped; } 

this is the function i've created to return a string/sentence without whitespaces. using this function as a void function and simply printing the stripped string works, but this iteration of the code returns (null). i am somewhat of a newbie to C so simple solutions to solve this problem would be appreciated. Thanks!

3
  • 1
    Did you mean char* stripper(char x[])? You've defined the function to return a char. Also, stackoverflow.com/q/122616/2970947 Commented Oct 4, 2022 at 4:50
  • 1
    You can't return a local array from a function. Commented Oct 4, 2022 at 4:52
  • You also shouldn't be calling strlen on each end every iteration of the loop (unless you want it to run vastly slower). Take the length once, before entering the loop. It's just common sense. Commented Oct 4, 2022 at 5:37

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.