help with c code
I am trying to write an entire structure into afile. But when i uuse
error : fwrite has one less argument happens
where ve is structure variable and fp is file descriptor.
soI put one more argument
and segmentation error comes............please help.. :D
Maybe try write instead?
Also, I don't know about your "sizeof(ve)". I prefer the notation "sizeof( struct myStruct )"
$ man 2 write
ssize_t write(int fd, const void *buf, size_t count);
More understandable IMHO.
As for the segfault, did you open the file first?
sizeof(ve) is perfectly good C. I really do agree with you, caffeine, but on the other hand sizeof(ve) holds up even if you change the type of ve.
Cool. I always thought it was a weird side effect that just happened to work, but I guess not. How does sizeof work if you change the type of a variable? Wouldn't sizeof simple return the sizeof the type the variable is declared as? What happens if you cast a void * to a some structure and call sizeof? I guess I'll have to test! ;-)
Now, I haven't examined sizeof that closely, but I guess that if you don't pass it a type name, it evaluates the expression inside the parentheses and returns the size of the final type of it. That means, of course, that sizeof((void *)ve) would return 4 on any IA32 architecture. Always remember, though, that sizeof isn't a function, but a language keyword.
Yeah. I think the preprocessor actually substitutes calls to it with the actual size before the code is compiled.
Oh no. The preprocessor does nothing with it. Remember, it couldn't possible evaluate variables.