I'm trying desperately to figure this out.
In Visual Basic I use split() function. In C there is none!
Or is it?
Dim txtData As String = SerialPort1.ReadLine
RichTextBox1.Text = txtData
Dim myFile As String = txtData
myFile = Replace(myFile, " ", "")
Dim i As Integer
Dim aryTextFile() As String
aryTextFile = myFile.Split(",")
'Sett inn sensorene her
For i = 0 To UBound(aryTextFile)
How could I do this in C?
MMh, you want to read Serial and get its values into an array... it seems so to me.
So you have to declare an array, and then simply put the values into it.
ahm, seems that you want to get rid of " "....
First Step I think...
char myvalues[count of Values]; // Declare a Array with X cells.
int counter=0; // Declare a counter which holds ints
Serial.beginn(19200); //Serial.open with 19200 Speed.
myvalues[counter]=Serial.read(); //Read a Value and put it into the Array.
counter++; // Increase Counter to get to the next Arraycell.
delay(50); // This slows down, to avoid a bufferoverrun.
Thats maybe buggy (not tested),
AND it's NOT the best way....
but with this in scheme you should get
the serial incomming Values into a onedimensional Array.
Hope, this is a startingpoint for you.
Sure but not every Microcontroller have 1K...
Stringmanipulation has been introduced with 021 022 officially.
I am using a 1284p with 16KB Sram and 128KB flash for example.
Simple manipulation is possible i think.
The strtok function can be used, in a while loop, to extract tokens that are delimited by any character(s).
char test = "This is a string with many words";
char *token = strtok(test, " ");
// token will be "This"
// Do something with this word
token = strtok(NULL, " "); // Use NULL as the 1st argument to keep parsing the same string
// token will be is, a, string, etc. in order