bywuu
 
 
  Joined: 04 Aug 2011 Posts: 29
 
  | 
		
			
				 Posted: Tue Jan 31, 2012 8:29 am    Post subject: Maybe this is a stupid question... | 
				     | 
			 
			
				
  | 
			 
			
				Hi,
 
Now I want to know the position of the second comma in my string ,let's say the string is:"123456789,546321874541321,111",if I write this:
 
 	  | Code: | 	 		  
 
u8 endPos = 10;//the first comma position is set
 
u8 p[] = "123456789,546321874541321,111";
 
     while(p[endPos]!=','){
 
         endPos++;
 
     }
 
     memcpy(phoneNum,p+10,endPos-10);
 
 | 	  
 
it is fine,but if I write this:
 
 	  | Code: | 	 		  
 
u8 endPos = 10;//the first comma position is set
 
u8 PROGMEM myProductStr[]="123456789,546321874541321,111";
 
while(myProductStr[endPos]!=','){
 
         endPos++;
 
     }
 
     memcpy(phoneNum,myProductStr+10,endPos-10);
 
 
 | 	  
 
it just hang...even if I changed it into:
 
 	  | Code: | 	 		  
 
while(rb(myProductStr[endPos])!=','){
 
 | 	  
 
it still not work...I know it must be something about the PROGMEM.
 
So what is the correct methord?How to do it?
 
I now using a stupid way:
 
 	  | Code: | 	 		  
 
u8 * p = malloc(1);
 
    memcpy(p,myProductStr+endPos,1);
 
    p[1]=0;
 
    while(p[0]!=',')
 
        {
 
            endPos++;
 
        memcpy(p,myProductStr+endPos,1);
 
            p[1]=0;
 
        }
 
    free(p); 
 
 | 	  
 
 
Do you have any better idea?
 
Thanks | 
			 
		  | 
	
	
		pz
 
 
  Joined: 12 Mar 2004 Posts: 1161
 
  | 
		
			
				 Posted: Wed Feb 01, 2012 10:54 am    Post subject:  | 
				     | 
			 
			
				
  | 
			 
			
				 	  | Code: | 	 		  
 
 
u8 PROGMEM myProductStr[]="123456789,546321874541321,111";
 
 
void somefnc()
 
{
 
u8 endPos = 10;//the first comma position is set
 
 
while(rb(myProductStr+endPos)!=','){
 
         endPos++;
 
     } 
 
....
 
}
 
 | 	  
 
 
So have the  myProductStr[] out of call and rb() is a must. | 
			 
		  |