expected primary-expression & obtaining substrings
hopefully can show me 'best way' substrings.... plans return pointer new string assign currenttext to....
but real problem getting pesky "error: expected primary-expression before 'char'" , pointing @ 'char substr(' on bottom.....
here's code....
but real problem getting pesky "error: expected primary-expression before 'char'" , pointing @ 'char substr(' on bottom.....
here's code....
code: [select]
#include <mlcd.h>
char scrolltext[255] = "\0";
char currenttext[255] = "\0";
char tmpstr[255] = "\0";
int curpos = 0;
int curdir = 1;
mlcd mlcd(19200);
char substr(*char, int, int);
void setup()
{
mlcd.start();
mlcd.clrscrn();
strcat(scrolltext, "bluegrass digital inc.");
}
void loop()
{
while (1)
{
if (curdir == 1)
{
strncat(currenttext, &scrolltext[curpos], 1);
}
if (strlen(currenttext) > 16)
{
//strncpy(currenttext, *(¤ttext+1), 16);
}
if (curpos < strlen(scrolltext)) {curpos += curdir;} else {curdir = -1;}
mlcd.setcursor(16 - strlen(currenttext), 1);
mlcd.sendtext(currenttext);
delay(200);
}
}
char substr(*char srcstr, int start, int length)
{
}
not sure 'best way' assuming want substr create new string, done follows (note * follows char):
don't forget should free string when done if want reuse memory
code: [select]
char* substr(char* srcstr, int start, int length)
{
// need allocate memory new string, can using malloc:
char* newstring = (char*)malloc(length+1);
if(newstring) { // check malloc able allocate memory
strncpy(newstring,&srcstr[start], length); // copy source string
newstring[length] = '\0'; // make sure there terminating 0
}
return newstring;
}don't forget should free string when done if want reuse memory
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > expected primary-expression & obtaining substrings
arduino
Comments
Post a Comment