D
David. E. Goble
Hi all;
I have a function that reads in a list of filenames wrps them in
javascript and ten writes them to a file. It all works, now I want to
randomly store one for later use. But the string has extar garbage on
the end of it.
EG mymenu infile test
Read in
007.gif
1luvu.gif
1zhelp.gif
22_yikes.gif
2evil.gif
test.jpg
2twocents.gif
321.gif
test.html
ak47.gif
ald.gif
alien.gif
angry.gif
and randomly pick one and store in char afile[]. Lets say we select
randomly test.jpg. The output should be;
testImages[0]="test/007.gif"
testImages[1]="test/1luvu.gif"
testImages[2]="test/1zhelp.gif"
testImages[3]="test/22_yikes.gif"
testImages[4]="test/2evil.gif"
testImages[5]="test/test.jpg"
testImages[6]="test/2twocents.gif"
testImages[7]="test/321.gif"
testImages[8]="test/ak47.gif"
testImages[9]="test/ald.gif"
testImages[10]="test/alien.gif"
testImages[11]="test/angry.gif"
afile = test/test.jpg
But it ends up as test/test.jpg/ald.gif
Here is the function;
int myheader(FILE **infile, FILE **header, char b[], char afile[])
{
char line[LINESIZE]="\0";
char base[LINESIZE]="\0";
int i=0;
strcpy(afile, "\0");
fprintf(*header, "<script type=\"text/javascript\">\n\n");
fprintf(*header, "%sImages=new Array()\n\n", b);
while(fgets(line, LINESIZE, *infile)!=NULL)
{
line[strlen(line)-1] = '\0';
if(strstr(line, ".gif")!=NULL || strstr(line, ".jpg")!=NULL)
{
strcpy(base, b);
strcat(base, "/");
strcat(base, line);
if(!rand()%1) strcpy(afile, base);
fprintf(*header, "%sImages[%d]=\"%s\"\n", b, i++, base);
}
}
therest(header, b);
return 0;
}
Regards David. E. Goble
http://www.pnc.com.au/~degoble
degoble[AT]pnc.com.au | dgoble[AT]pnc.com.au
Po Box 648 (9 Murray St), Kingscote, Kangaroo Island SA 5223
I have a function that reads in a list of filenames wrps them in
javascript and ten writes them to a file. It all works, now I want to
randomly store one for later use. But the string has extar garbage on
the end of it.
EG mymenu infile test
Read in
007.gif
1luvu.gif
1zhelp.gif
22_yikes.gif
2evil.gif
test.jpg
2twocents.gif
321.gif
test.html
ak47.gif
ald.gif
alien.gif
angry.gif
and randomly pick one and store in char afile[]. Lets say we select
randomly test.jpg. The output should be;
testImages[0]="test/007.gif"
testImages[1]="test/1luvu.gif"
testImages[2]="test/1zhelp.gif"
testImages[3]="test/22_yikes.gif"
testImages[4]="test/2evil.gif"
testImages[5]="test/test.jpg"
testImages[6]="test/2twocents.gif"
testImages[7]="test/321.gif"
testImages[8]="test/ak47.gif"
testImages[9]="test/ald.gif"
testImages[10]="test/alien.gif"
testImages[11]="test/angry.gif"
afile = test/test.jpg
But it ends up as test/test.jpg/ald.gif
Here is the function;
int myheader(FILE **infile, FILE **header, char b[], char afile[])
{
char line[LINESIZE]="\0";
char base[LINESIZE]="\0";
int i=0;
strcpy(afile, "\0");
fprintf(*header, "<script type=\"text/javascript\">\n\n");
fprintf(*header, "%sImages=new Array()\n\n", b);
while(fgets(line, LINESIZE, *infile)!=NULL)
{
line[strlen(line)-1] = '\0';
if(strstr(line, ".gif")!=NULL || strstr(line, ".jpg")!=NULL)
{
strcpy(base, b);
strcat(base, "/");
strcat(base, line);
if(!rand()%1) strcpy(afile, base);
fprintf(*header, "%sImages[%d]=\"%s\"\n", b, i++, base);
}
}
therest(header, b);
return 0;
}
Regards David. E. Goble
http://www.pnc.com.au/~degoble
degoble[AT]pnc.com.au | dgoble[AT]pnc.com.au
Po Box 648 (9 Murray St), Kingscote, Kangaroo Island SA 5223