Opening a file in C in write mode -
i writing c program converts text file binary file , vice versa. first question have opening file in "w" mode. there need have check output file opened correctly?
file *output; output = fopen("output.bin", "w"); if(output == null) { printf("error opening output file\n");}
basically question whether or not output ever == null. because if there problem opening output wouldn't create new file named "output.bin"?
also other question how characters saved in binary file. know i'm supposed save each character unsigned char can have values between 0 , 255 , should write char output file. actual logical path of how happens not making sense if can me or point me in right direction appreciate it!
yes, opening file in write mode might still fail. here's bunch of possible reasons, not ones:
- you don't have permission create or change file.
- the file read-only, or directory in read-only.
- the file inside file. (
test/foo
iftest
file , not directory) - the filesystem out of space or inodes (on filesystems have fixed number of inodes)
- the user has hit disk space quota.
- the file on computer, , network down.
- the filename invalid - such
c:/???*\\\\foo
on windows. - the filename long.
Comments
Post a Comment