Mail Archives: djgpp/1997/09/18/23:17:38
David Lenk wrote:
> This is the of code from a program that I have been trying to write. I
> need a way of makeing a filename and storing it in a variable so that it
> can be used in a fprintf or fwrite command. I ask if you could please
> anotate the source if you decide to post any.
>
> #include <stdio.h>
> #include <conio.h>
>
> void main()
> {
> int nRanda, table,A, B;
what are you A,B of type integer declaring for??
>
>
> for (table = 1; table <9; table++)
> {
> nRanda = (rand() % 99999999);
9 times assigning a random value in nRanda, purpose?
> {
> char A[] = "this will be in the file.";
better devlare this A at start of main, instead ofstrange A,B of type
integer.
> char B = nRanda; // B should hold the file name
Man, B must be a string, an array of chars!!!Not a character.
> FILE*fp;
> fp = fopen(B, "w");
> fwrite(A, sizeof A, 1, fp);
> fclose(fp);
> }
> }
> }
>
> PS I write for DOS.
> --
> Thanks in advance for all your help!
>
> David Lenk, ~SamWise~
> lenkd AT pltpub DOT com
> www.pltpub.com/lenkd
Here look, a code for generating random filename into FileName:
char FileName[13];
int i;
for (i=0;i<8;i++) FileName[i]=rand()%('z'-'a'+1)+'a';
FileName[8]='.';
for (i=9;i<12;i++) FileName[i]=rand()%('z'-'a'+1)+'a';
FileName[12]='\0';
thats it.
- Mark
- Raw text -