Hi all. I'm starting to learn Linux programming and my first bit of code using a system call is not responding the way I expected it to.
It's the write() call. Here's the code:
if ((write(1, "Here is some data.......\n", 18)) != 18)
write(2, "A write error has occurred on file descriptor 1\n",48);
The code seems simple enough. The evaluation of "!=18" should force the following statement to execute if the count is not exactly 18. But that doesn't happen when I alter the string to a shorter or longer sentence.
The statement following the IF evaluation never executes, no matter what. The first string will truncate if the string is longer than the count, and if the string is shorter than the count, the string will print, and then the letter 'A'
and a space is printed as a prefix to the next command line prompt.
So why isn't the function acting as expected? Any help is appreciated!