On Fri, 20 Jul 2001, Lawrence Lile wrote: > I am perpetually confused by pointers in C, thus, I avoid them whenever > possible. (I have the same method of coping with the city bus system - > don't use it) I was the same way until I forced myself to read and re-read the K&R C book until I understood them. Now I'm not afraid to use them - as long as I have the book on hand, since I need to re-read it nearly every time! 8-) > CCS has a number of string functions, which "return pointers" whatever that > means. What I'd like to accomplish is this: > > I want to concatenate several items into a string, then pass that string to > PRINTF and squirt it out the RS232 port. > > One of the strings might be something like "10:01 AM System ON" or " 7 28 > PM System OFF" (note the blinked colon) > > Here's a stab at it, prolly fulla bugs: > > Char string1[20]; > . > . > . > > STRCAT(string1, Hours); // of course, Hours is an INT, not a string, how to > convert to a string? Of course there's an atoi() function (ASCII to int) but no itoa(). That's what printf is for. You could write your own itoa(), or figure out how to use printf() for it. In any case, strcat() needs two pointers, you can't pass it the actual value of Hours. You would have to do strcat(string1,&hours); instead... BUT since Hours is an int, not a string, so that's not good. > STRCAT(string1, ':'); // blinky colon > STRCAT(string1, Minutes); // minutes, also still an INT not a string ??? > STRCAT(string1, 'PM'); // does this work with a buncha letters? Nope. I do this: char buffer[10]; strcpy(buffer, "PM"); strcat(string1, buffer); Note that I don't use *buffer, buffer is already a pointer to the start of the array buffer[10]. > etc. > Printf(*string1); // ?????????? Nope, printf(string). String is already a pointer to the char array. > > Any suggestions are welcome I feel your pain. I'd be very tempted to abandon strcat() and instead build a better mousetrap. Use strlen() to find the end of the string, then append whatever you want to it. You can then use printf() to send ASCII-converted numbers to that function. Hey, that's a neat idea... I think I'll write it! I've been needing it for a long time anyway. Dale -- A train stops at a train station. A bus stops at a bus station. On my desk I have a workstation... -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu