Loading a text file problem...

Non-platform specific questions.

Loading a text file problem...

Postby BeyondtheTech » Sat Jun 18, 2005 6:44 am

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?
User avatar
BeyondtheTech
 
Posts: 270
Joined: Wed Mar 30, 2005 6:34 am
Location: Edison, NJ
Score: 4 Give a positive score

Postby makslane » Sun Jun 19, 2005 12:12 am

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);
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby BeyondtheTech » Tue Jun 21, 2005 2:36 am

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.
User avatar
BeyondtheTech
 
Posts: 270
Joined: Wed Mar 30, 2005 6:34 am
Location: Edison, NJ
Score: 4 Give a positive score

Postby makslane » Tue Jun 21, 2005 2:11 pm

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
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby makslane » Tue Jun 21, 2005 2:13 pm

The fgets will include the newline on returned string.
To remove the newline use:

vendorname[strlen(vendorname) - 1] = 0;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest