Breaking down a string

Is there code that could break down a string??
I want to make a plotter and I have functions for every letter and number. I want to create a string in the computer that will be displayed on the vex iq screen. I want the robot to take that string and break it apart letter by letter and write it down. I named each function by letter. I don’t want to have to type each letter’s function just to write the word.

so is there code that could break down a string??

thx monkeyboy250

Are you using RobotC or some other environment like C++?

In RobotC you can have a function similar to this one:

void plot_string(const char* str)
    int i;
    char c;

    // read null terminated string one character at a time
    for( i=0 ; (c=str[i])!=0 ; i++ ) 
      if(      c == ' ' ) plot_space();
      else if( c == 'A' ) plot_A();
      else if( c == 'B' ) plot_B();
      else if( c == 'C' ) plot_C();
      else if( c == 'Z' ) plot_Z();

void main(void)
   plot_string("HELLO VEX!");

If you want to make it less typing an more fancy computer science, then there is a way to declare some data structures and store the shapes of the letters in them instead of having separate functions and long sequence of the if() statements.


If you are using C++, include string.h and use substrings:

Im using RobotC for this project

@weilin can I just copy that code and name each of the functions plot_A and plot_B. So basically that code will take “Hello Vex” and break the string apart right.

Yes, that should work. Jjust be mindful that, unless you have separate function to plot upper and lower case letter, you may need to do something like this:

  else if( c=='A' || c=='a' ) plot_A();
  else ...

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.