c - what is added first '\n' or '\0' -


when working of character strings. have this:

#include <stdio.h>  #define maxline 1000   main(){ int c;  int i=0; char s[maxline];   while(c=(getchar()) !=eof)  { s[i] = c;  ++i;  }  } 

i want ask after write hello , hit enter break line '\n' adds first after character stream or null terminating character i.e. '\0'

visually 1 correct representation of what's happening: (1) hello\n\0 or (2) hello\0\n

the way code written, there no nul character added s.

since reading input 1 character @ time, if want s nul-terminated you'll need add nul yourself.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -