View unanswered posts | View active topics It is currently Tue Sep 02, 2014 11:40 am






Reply to topic  [ 6 posts ] 
String problems 
Author Message
Rookie

Joined: Fri Feb 29, 2008 8:12 pm
Posts: 3
Post String problems
Hi, I am having problems using strings. I need to be able to access the individual characters of a string by index. Are there any library functions that I missed that could do this, or are there other methods?


Fri Feb 29, 2008 8:15 pm
Profile
Rookie

Joined: Fri Feb 29, 2008 8:12 pm
Posts: 3
Post 
I need to be able to access the individual characters of the string, or to convert the string into a byte array or something similar.


Sun Mar 02, 2008 4:06 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
Eventually ROBOTC will allow string access the same way that you access a array of char. The current workaround is to "memcpy" the string to a 'char[20]" array, manipulate the array and then 'strcpy' the result back. Here's an example.
Code:
string sTemp;
char   sArray[20];

task main()
{
  int i;
 
  memcpy(sArray, sTemp, sizeof(sArray));
  for (i = 0; i < 10; ++i)
    sArray[i] = '0' + i;
  sArray[10] = 0; // end of string termination
  strcpy(sTemp, sArray);
  return;
}

This does require a new version of the 'strcpy' intrinsic if you are using version earlier than 1.17. The new version is
Code:
intrinsic void strcpy(void &pToBuffer, const void &pFromBuffer)
                      asm(opcdSystemFunctions,
                          byte(sysFuncStrCpy),
                          variableRefRAM(pToBuffer),
                          variableRefRAM(pFromBuffer));


Tue Mar 04, 2008 10:30 am
Profile
Rookie

Joined: Fri Feb 29, 2008 8:12 pm
Posts: 3
Post 
I inserted the code and the modified strcpy function, but when I compiled, RobotC crashed. Now, whenever I start RobotC, after I click "Evaluate RobotC," the main screen briefly appears and then the program crashes.

I am tried using the beta version, but the beta does not support strings. Also, in the beta, when I try to create too many int arrays like
Code:
int temp7[7][5]=
                         {{1,0,0,0,1},
      {1,0,0,0,1},
      {1,0,0,0,1},
      {1,1,1,1,1},
      {1,0,0,0,1},
      {1,0,0,0,1},
      {1,0,0,0,1}};



I get the error

Code:
**Severe*:Out of memory for variable allocation.


My arrays complied fine in v 1.10.


Tue Mar 04, 2008 6:04 pm
Profile
Site Admin
Site Admin

Joined: Wed Jan 24, 2007 10:42 am
Posts: 602
Post 
Dick will have to field the issue about the memory allocation and running out of space.

As for the Beta and not launching (crashing as soon as it opens), you can alleviate this is issue by deleting your ROBOTC registry. ROBOTC remembers the last file you had opened and compiles it when ROBOTC opens.

To delete the registry manually, follow these steps:
1. Go to "Start" then "Run" then type "regedit"
2. Navigate to: HKEY_CURRENT_USER\Software\Robotics Academy
3. Delete this entire Key Folder...close regedit.
4. Open ROBOTC for Mindstorms again, this will generate new registry keys and reset ROBOTC back to Day 1.

_________________
Timothy Friez
ROBOTC Developer - SW Engineer
tfriez@robotc.net


Tue Mar 04, 2008 7:35 pm
Profile
Creator
Creator

Joined: Fri Feb 09, 2007 9:21 am
Posts: 615
Post 
When you provide an isolated code snippet that compiles fine like
Code:
int temp7[7][5]=
     {{1,0,0,0,1},
      {1,0,0,0,1},
      {1,0,0,0,1},
      {1,1,1,1,1},
      {1,0,0,0,1},
      {1,0,0,0,1},
      {1,0,0,0,1}};

then I cannot diagnose your problem! You need to send me the complete file (dickswan@sbcglobal.net).

I suspect you're encountering an issue where temporary working variables cannot be allocated if you already have more than 256 words of user declared variables within a code block. You could verify this by moving some variables out of procedure declaration to global scope and seeing if this clears up the problem. Alternatively some of the variable might be appropriate to declare with the "static" keyword.

This issue will be fixed in an upcoming release. I just noticed it yesterday.


Tue Mar 04, 2008 8:05 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.