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!

Arsenic
  • 1
  • 3
  • 1
    Did you mean `char* stripper(char x[])`? You've defined the function to return a `char`. Also, https://stackoverflow.com/q/122616/2970947 – Elliott Frisch Oct 04 '22 at 04:50
  • 1
    You can't return a local array from a function. – Barmar Oct 04 '22 at 04: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. – Tom Karzes Oct 04 '22 at 05:37

0 Answers0