Hello!
Im a fresh C programmer, and have a issue with this code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
int returnValue;
uid_t uid;
main( int argc, char* argv[] )
{
struct stat *filstat;
returnValue = fstat( open(argv[1], O_RDWR ), filstat );
if(returnValue != 0) {
perror("Error");
exit(1);
}
uid = filstat->st_uid;
exit(0);
}
Like this, the code works. BUT, if I move line 9, uid_t uid; to say line 14, just before returnValue =... it doesnt work! The error I recieve is:
Error: Bad address
We and two buddies have been fickling with this issue for two hours now, not understanding why it wont work.
Do you have any ideas?
Also, this code works on OSX Tiger 10.4.9 (gcc 4.0.1), but not on Fedora 6 (gcc 4.1.2), which gets a Segmentation Fault.