I think the subject of this thread is probably wrong. But basically I've written a program to print out exactly what I wanted to stdout, but having trouble writing to a file.
The codes I have written is slightly different as I have included system() to run a unix command.
Here's a small part of my code (slightly different to my original code to advoid confusions):
char namegen[20000];
for (i=1; i <= 3; i++) {
printf ("%d\t", rand() % 5000);
sprintf( namegen, "cat /dictionaryfile | head -631 | tail -1");
fflush(stdout);
system (namegen);
}
the cat /dictionaryfile | head -631 | tail -1
is a unix command which looks in the file "dictionaryfile" and prints out the 631th word, I have no idea what the tail -1 is hehe, but forget about that
the fflush(stdout) is to synchronise the printf() and system() commands
now what my program can do right now is print 3 random numbers with the 631th word from the dictionary file, eg
235 chicken
224 chicken
446 chicken
each word seperated by a tab
what I want to do now is store these into a file, which I don't really know how to
so far I have
FILE *myfile;
myfile = fopen( "myfile.txt", "w");
and then I've tried using fwrite etc, and don't seem to be able to store the data into the file.
If anyone have any suggestion, please reply
Thanks,
Will



LinkBack URL
About LinkBacks



