You are telling the write call (which is not looking for null terminated strings) to write up to 1024 bytes but only providing 11 bytes to be written. write will happily try to continue to read from wherever "hello first" is stored in memory for 1024 bytes. Since constant strings are usually stored together in memory in an executable file you end up writing all of the constant strings from the program into your file.
To see what I mean, try the following change:
char msg[] = "hello first";
/* ... */
nob = write (fd, msg, 1024);
and examine what changes.
When you call write you need to provide the amount of data you want writtenexactly. So something like nob = write (fd, msg, strlen (msg));
L7Sqr
Practically a Master Poster
657 posts since Feb 2011
Reputation Points: 201
Solved Threads: 124