Page 1 of 1

Loading a text file problem...

PostPosted: Sat Jun 18, 2005 6:44 am
by BeyondtheTech
I have a file called "vendor.dat" that contains two lines in ASCII. The first line is a "trigger" and the second line is a "URL."

Basically, it contains this:
Code: Select all
pocketgear
http://www.pocketgear.com/software_detail.asp?id=17928



In my program, it has three logos, and it will display the logo corresponding to the vendor based in the vendor.dat file, and activate the URL upon clicking on it.

Code: Select all
FILE *arq = fopen("vendor.dat", "r");

strcpy(vendorname,"pocketgear");
strcpy(vendorurl,"http://www.pocketgear.com/software_detail.asp?id=17928&associateid=326");

if(arq)
{
    fgets(vendorname, 255, arq);
    fgets(vendorurl, 255, arq);
}

fclose(arq);

if (strcmp(vendorname,"handango")>0) ChangeAnimation("vendor","handango",FORWARD);
if (strcmp(vendorname,"pdatopsoft")>0) ChangeAnimation("vendor","pdatopsoft",FORWARD);
if (strcmp(vendorname,"pocketgear")>0) ChangeAnimation("vendor","pocketgear",FORWARD);



This works in Windows, but the PocketPC always defaults to the middle one, regardless of setting. Why is that?

PostPosted: Sun Jun 19, 2005 12:12 am
by makslane
Try this:

Code: Select all
FILE *arq = fopen("vendor.dat", "r");

if(arq)
{
    fgets(vendorname, 255, arq);
    fgets(vendorurl, 255, arq);
    fclose(arq);
}



if (strcmp(vendorname,"handango")==0) ChangeAnimation("vendor","handango",FORWARD);
if (strcmp(vendorname,"pdatopsoft")==0) ChangeAnimation("vendor","pdatopsoft",FORWARD);
if (strcmp(vendorname,"pocketgear")==0) ChangeAnimation("vendor","pocketgear",FORWARD);

PostPosted: Tue Jun 21, 2005 2:36 am
by BeyondtheTech
I tried it again with 1.3.0 and created test.textNumber to equal the strcmp result.

On the desktop, I get values such as -1 and 1, but on the PocketPC, I get weird results like 8 and 2816.

Looks like a bug.

PostPosted: Tue Jun 21, 2005 2:11 pm
by makslane
Is not a bug. The strcmp definition is this:

int strcmp(const char * s1, const char * s2)

return < 0 if string1 less than string2
return 0 if string1 identical to string2
return > 0 if string1 greater than string2

So, you can't consider the absolute values, but your sign

http://www.mkssoftware.com/docs/man3/strcmp.3.asp
http://www.opengroup.org/onlinepubs/007 ... trcmp.html
http://msdn.microsoft.com/library/defau ... mbscmp.asp

PostPosted: Tue Jun 21, 2005 2:13 pm
by makslane
The fgets will include the newline on returned string.
To remove the newline use:

vendorname[strlen(vendorname) - 1] = 0;