title: Why malloc can't work with strcpy?
body: <pre><code>char * removeChar(char * str, char c){
      int len = strlen(str);
      int i = 0;
      int j = 0;
      char * copy = malloc(sizeof(char) * (len + 1));
      while(i &lt; len){
          if(str[i] != c){
              copy[j] = str[i];
              j++;
              i++;
          }else{
              i++;
          }
     }
  
      if(strcmp(copy, str) != 0){
          strcpy(str,copy);
  
      }else{
          printf("Error");
      }
      return copy;
  }
  
  
  
  
  int main(int argc, char * argv[]){
      char str[] = "Input string";
      char * input;
      input = removeChar(str,'g');
      printf("%s\n", input);
      free(input);
      return 0;
  }
  </code></pre>
  
  <p>I don't know why every time I try to run it ,it always says uninitialized variable and sticks in the strcpy line and printf line.</p>
  
  <p>Basically this function is to take a string, and a character and removes the  that character from the string (because I am learning malloc so that's why I wrote the function like this).</p>