Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (Aku_Aku, 7th_zorro, Ayumi), 1,050 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Problem with a (hidden) endless LOOP #201662
04/10/08 14:06
04/10/08 14:06
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
pararealist Offline OP
Senior Member
pararealist  Offline OP
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
Hello all,

I am having a problem with an endless loop that i only discovered
when i inserted a printf into the loop.
I have packed it into a function, all you have to do is create a little
program and call fDoTest() from main.

The function should remove the path leaving the filename
then remove the .wmb extension from filename and add .gsx
extension to the filename.

 Code:
// filled for testing - usually comes from fileselect dialog
char* filePathName = "D:\\GSTUDIO PROJECTS\\A7_PROJECTS\\PROJECTTEST\\atestfile.wmb";   // 
//
STRING* aCurrentPath = " ";
aCurrentPath = str_create("aCurrentPath");
STRING* camPosName_str = " ";  
camPosName_str = str_create("camPosName_str");

///////////////////////////////////////////////////////////////
function fDoTest()
{
	
draw_text("in fDoTest()",500,200,_vec(0,255,0 ));
	
	int i = 0, j=0;
	int count=0, len=0;
	int pcount = 0;
	// THIS LOOP seems to never end ????????????
	// is strange - only found out whilst debugging
	// yet app works (at least up to now) 
	// but is definately not right
	// if i insert a printf in the while loop then i notice it	
	while (str_stri(_str(filePathName),"*") == 0)
	{	            
		// search for "\" until no more
		len = str_len(_str(filePathName));
		count = str_stri(_str(filePathName),"\\");
		pcount = len-count;					
		// clip name from begin to "\"
		str_clip(_str(filePathName),count);
 		// trunc name from end by (pcount - to "\") dont work ????
		str_trunc(_str(aCurrentPath),pcount );				
	        // store levelname
		str_cpy(camPosName_str,_str(filePathName));	
		// split levelname. from ext (wmb))
		len = str_len(camPosName_str); 
		count = str_stri(camPosName_str,"."); // search for "."
		count = (len - count);
		str_trunc(camPosName_str,count);						
		//  
		// add file ext (gsx) )
		str_cat(camPosName_str,"gsx");	
		//
		//
// UN-COMMENT next line to see printf in endless loop
// and i have to end printf in task manager
// yet COMMENTED runs ok
//printf("camPosName_str= %s",_chr(camPosName_str));		
		//
      wait(1);
   }
   // DOES NOT seem to get to here
   printf("aCurrentPath= %s",_chr(aCurrentPath));   
   printf("camPosName_str= %s",_chr(camPosName_str));
   
   return;
} 


Thanks for any help. I just cant see (at this time) the reason.


A8.3x Commercial, AcknexWrapper and VS 2010 Express
○pararealist now.
Re: Problem with a (hidden) endless LOOP [Re: pararealist] #201679
04/10/08 15:28
04/10/08 15:28
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline
Expert
Excessus  Offline
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
everytime you use _str, it creates a new temporary string. The variable filePathName never changes, so the condition will always stay true if it was at the beginning of the loop.

Also, why is there a wait(1) in that loop?

Re: Problem with a (hidden) endless LOOP [Re: Excessus] #201681
04/10/08 15:45
04/10/08 15:45
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
pararealist Offline OP
Senior Member
pararealist  Offline OP
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
Hi,

while
{

wait(1);
}
you need wait(1) in while loop i thought.
//
so i would need to use a do while loop with the condition at the end?
or how else can seperate the filename from the full pathname
and then remove the extension to add another (diferent) extension?


A8.3x Commercial, AcknexWrapper and VS 2010 Express
○pararealist now.
Re: Problem with a (hidden) endless LOOP [Re: pararealist] #201685
04/10/08 15:55
04/10/08 15:55
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
pararealist Offline OP
Senior Member
pararealist  Offline OP
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
forgot to say i add
str_cpy(aCurrentPath,filePathName);
before loop.

in loop i use the pcount var to
get the length.
but now i see that i should have used?
// store levelname
str_cpy(camPosName_str,_str(aCurrentPath));
instead of
// store levelname
str_cpy(camPosName_str,_str(aCurrentPath));

will try this again.


A8.3x Commercial, AcknexWrapper and VS 2010 Express
○pararealist now.
Re: Problem with a (hidden) endless LOOP [Re: pararealist] #201686
04/10/08 15:56
04/10/08 15:56
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
pararealist Offline OP
Senior Member
pararealist  Offline OP
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
IGNORE LAST

forgot to say i add
str_cpy(aCurrentPath,filePathName);
before loop.

in loop i use the pcount var to
get the length.
but now i see that i should have used?
// store levelname
str_cpy(camPosName_str,_str(aCurrentPath));
instead of
// store levelname
str_cpy(camPosName_str,_str(filePathName));

will try this again.


A8.3x Commercial, AcknexWrapper and VS 2010 Express
○pararealist now.
SOLVED: Problem with a (hidden) endless LOOP [Re: pararealist] #201742
04/10/08 20:56
04/10/08 20:56
Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
pararealist Offline OP
Senior Member
pararealist  Offline OP
Senior Member

Joined: Dec 2006
Posts: 434
UK,Terra, SolarSystem, Milky W...
SOLVED
Decided to use a for LOOP.

 Code:
 
function fDoTest()
{	
	int i = 0;
	int count=0, len=0;
	int pcount = 0;	
	//
	str_cpy(aCurrentPath,filePathName);
	//	
	// get length of filePathName
	len = str_len(_str(filePathName));
	for (i = 0; i < len; i++) 
	{
		// search for "\" until no more
		count = str_stri(_str(filePathName),"\\");
		pcount = len-count;	
		// clip name from begin to "\"
		str_clip(_str(filePathName),count);				
	   // store levelname
		str_cpy(camPosName_str,_str(filePathName));	
		// split name. from ext (wmb))
		len = str_len(camPosName_str);
		// search for "." 
		count = str_stri(camPosName_str,"."); 
		count = (len - count);
		// truncate it
		str_trunc(camPosName_str,count);						
		//  
		// add file ext (gsx) )to get campos filename for this level
		str_cat(camPosName_str,"gsx");							
	}
	//   
   printf("camPosName_str= %s",_chr(camPosName_str));
   return;  
}



A8.3x Commercial, AcknexWrapper and VS 2010 Express
&#9675;pararealist now.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1