On 2002-06-30, Eliran wrote: > Hello ! > > I'm trying to use the command *fwrite()* (not write()) to write the content > of de->d_name (de is the structure name,) to a file, I have tried many ways > but it always get scrambled and I hear beeps (like trying to cat a binary > file). > > I'm using the "a" mode for fopen not "b".
For for me it works just fine, see the example below. My guess (since you didn't show your code..) is that you put the fwrite function arguments in the wrong place, because I think when it beeps, something gets written to your terminal (the terminal usually generates the beeps), ie, to file descriptor 1 or 2 -- sdtoud and stderr respectively. so it looks like you are not writing to the file you were thinking of. am I correct? The following code works just fine, if you supply an argument, that is. #include <unistd.h> #include <stdio.h> #include <sys/types.h> #include <dirent.h> int main(int argc, char ** argv) { DIR * dir = opendir(argv[1]); struct dirent * de; while(de = readdir(dir)) fwrite(de->d_name, strlen(de->d_name), 1, stdout); return 42; } ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]