UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« on: June 27, 2012, 10:57:07 am » |
Hi, I have been fumbling around with this code without any joy.... anyone able to put me right? I have a char "loggerName" and I want to add ".CSV" to make a new char "fileName.CSV" (needs to stay as a CHAR). I have tried lots of options but keen to keep it simple but just cannot figure out why this will not compile? char loggerName[10] = "AAAA_01"; char fileName[15] = (loggerName += ".CSV");
|
|
|
|
|
Logged
|
|
|
|
|
California
Online
Edison Member
Karma: 41
Posts: 1866
|
 |
« Reply #1 on: June 27, 2012, 11:25:20 am » |
Use strcat() I have tried lots of options but keen to keep it simple but just cannot figure out why this will not compile? Because there is no += operater for char arrays.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« Reply #2 on: June 27, 2012, 11:28:10 am » |
Thanks Arrch, I have tried using that but it produces a string which is not accepted by the next bit in the code: SD.open(fileName, FILE_WRITE);
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2351
|
 |
« Reply #3 on: June 27, 2012, 11:41:16 am » |
What does a serial.print tell you is in your filename variable? Also, post your code.
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« Reply #4 on: June 27, 2012, 12:11:18 pm » |
Not compiling is the issue I'm having.... below are the relevant code snippets and compile error: Code: char loggerName[10] = "AMAS_01"; char fileName[15] = (loggerName += ".CSV");
File dataFile = SD.open(fileName, FILE_WRITE);
invalid operands of types 'char[10]' and 'const char [5] to binary 'operator+'
|
|
|
|
|
Logged
|
|
|
|
|
New Jersey
Offline
Edison Member
Karma: 24
Posts: 2351
|
 |
« Reply #5 on: June 27, 2012, 12:15:50 pm » |
It's telling you you can't add character arrays together like that. Here's one way to do it: char loggerName[10] = "AMAS_01"; char fileName[15];
strcpy(filename, loggerName); strcat(filename,".CSV");
File dataFile = SD.open(fileName, FILE_WRITE);
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« Reply #6 on: June 27, 2012, 12:23:05 pm » |
Thanks - still getting a compile error? This message: expected cpnstructor, destructor, or type conversion before '(' token This line highlighted: strcpy(filename, loggerName);
|
|
|
|
|
Logged
|
|
|
|
|
Leeds, UK
Offline
God Member
Karma: 35
Posts: 983
Once the magic blue smoke is released, it won't go back in!
|
 |
« Reply #7 on: June 27, 2012, 12:28:09 pm » |
there was a typo in that code. The variable has a capital N char loggerName[10] = "AMAS_01"; char fileName[15];
strcpy(fileName, loggerName); strcat(fileName,".CSV");
|
|
|
|
|
Logged
|
~Tom~
|
|
|
|
UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« Reply #8 on: June 27, 2012, 12:37:06 pm » |
ooops... should have spotted that one :-)
Unfortunatley still getting the same compile problem (Arduino 0.22) for both the strcpy & strcat lines?
|
|
|
|
|
Logged
|
|
|
|
|
UK
Offline
Full Member
Karma: 0
Posts: 235
Arduino rocks
|
 |
« Reply #9 on: June 27, 2012, 12:43:37 pm » |
Ahhh.... got it.
I had the strcpy & strcat in the bit before void setup () (whatever that section is called?) - moved it to setup and it all works nicely.... thanks all for your help, appreciated :-)
|
|
|
|
|
Logged
|
|
|
|
|
California
Online
Edison Member
Karma: 41
Posts: 1866
|
 |
« Reply #10 on: June 27, 2012, 01:36:59 pm » |
Ahhh.... got it.
I had the strcpy & strcat in the bit before void setup () (whatever that section is called?) - moved it to setup and it all works nicely.... thanks all for your help, appreciated :-)
A good example of why it's best to post ALL your code.
|
|
|
|
|
Logged
|
|
|
|
|
SATX
Offline
Newbie
Karma: 0
Posts: 10
|
 |
« Reply #11 on: January 08, 2013, 11:08:06 pm » |
Just wanted to send a big thank you out to wildbill and Tom Carpenter et al for their help here. It FINALLY allowed me to manipulate my char arrays (4 of different sizes into one long string for my loop to run through) so I could display them on a serLCD from sparkfun, 16 chars at a time. Basically, simulating a scrolling effect on just a single line.
Thanks again, y'all rock.
|
|
|
|
|
Logged
|
|
|
|
|
|