low level I/O
I'm using the write() function something like this:
write(fildes, write_value, sizeof(n));
ie. I want to write a single integer value to filedes file. The integer is successfully written, but there is always a garbage value like t^@^@ appended to the end and I cannot understand why... by my (admittedly not rock solid) logic, only the correct number of bytes for an int should be written...
If someone could clue me in on the reason this happens, I should hopefully be able to fix it...
Are you expecting to be able to read the number in the text file? As you're using write() to output an int, the actual number will be written at a binary level, and won't be readable in a normal text viewer.
I must say, I'm really confused then, since I can read the proper number. There is some junk after it, however.
It seems like the two requirements, (a) that open, close, read, write are used and (b) that the file is a text file, conflict? All very confusing.
Sorry, it is my first time programming in C for an OS course and I feel like an idiot, but I'm just trying to do what I'm told :)
What are fildes, write_value, and n defined as?
n is an int passed to the function.
fildes is the file descriptor of an open file.
write_value = &n;
Post enough code for us to compile that shows your problem.