system
February 4, 2012, 7:03pm
1
How do you add chars together (concatenation)?
...
long randNumber;
char randWav[5] = {".wav"};
char randWav1[8];
randNumber = random(100, 400);
randWav1 = randNumber + randWav;
Serial.println(randWav1);
....
I get "incompatible types in assignment of 'char*' to 'char [8]'" on the randWaz1 = randNumber + randWav; line. What dumb newbie things am I doing or missing?
system
February 4, 2012, 7:03pm
2
You could try strcat, or sprintf
Bucky99:
How do you add chars together (concatenation)?
sprintf() is probably your friend here, as AWOL mentioned. Try doing it this way:
...
long randNumber;
char randWav1[10];
randNumber = random(100, 400);
sprintf(randWave, "%ld.wav", randNumber);
Serial.println(randWav1);
....
Incidentally, randNumber needn't be long. A regular int should do.
edit: fixed typo m-->,
system
February 4, 2012, 8:03pm
4
//strcpy(randWav,randNumber);
//
//sprintf(randWav,randNumber);
These give me - invalid conversion from 'long int' to 'const char*'
What does %ld do? And where can I learn about it and the strcpy/sprintf functions?
system
February 4, 2012, 8:05pm
5
Google's a useful starting point.
Here's a sprintf tutorial, hope it helps.
system
February 4, 2012, 8:24pm
7
Thank you for the replies and the resources.