Mon Aug 27, 2012 9:58 pm
int fileDescriptor = open ("/test.txt", O_APPEND);
FILE *filePointer = fopen ("/test.txt", "w");
File structure
typedef struct {
unsigned char *_ptr;
int _cnt;
unsigned char *_base;
unsigned char *_bufendp;
short _flag;
short _file;
int __stdioid;
char *__newbase;
#ifdef _THREAD_SAFE
void *_lock;
#else
long _unused[1];
#endif
#ifdef __64BIT__
long _unused1[4];
#endif /* __64BIT__ */
} FILE;
#include <stdio.h>
#include <fcntl.h>
int main()
{
int fileNumber;
FILE *filePointer;
fileNumber = open ("myfile.txt", O_WRONLY | O_CREAT);
if (fileNumber < 0)
{
printf("Can’t read file using file\n");
exit (1);
}
write (fileNumber, "Writing using File Number\n", 17);
filePointer = fdopen(fileNumber, "a");
fprintf(filePointer, "Writing using File Pointer\n");
fclose (filePointer);
close(fileNumber);
return 0;
}
fileNumber = fileno (filePointer);
write (fileNumber, "Writing using file descriptor \n", 17);
fclose (filePointer);
close(fileNumber);
Thu Feb 07, 2013 8:51 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.