title: Printing a string with null characters in it
body: <p>I take as input a string with spaces in it and replace the spaces with the NULL character '\0'. When I print the string now, I expect only the part till the first NULL character which was the first space earlier but I am getting the original string.</p>
  
  <p>Here is the code-</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  int main(){
      char a[1000];
      int length, i = 0;
      length = 0;
      scanf("%[^\n]s", a); 
      while(a[i]!='\0')
              i++;
      length = i;
      printf("Length:%d\n", length);
      printf("Before:%s\n", a); 
      for(i=0;i&lt;length;i++){
              if(a[i] == " ")
                      a[i] = '\0';
      }   
      printf("After:%s\n", a); 
      return 0;
  }
  </code></pre>
  
  <p>What is wrong in this?</p>