At 10:20 AM 7/20/01 -0500, you wrote: Hi, Lawrence (BTW, your toaster oven with LCD display, what temperature sensor does it use??- email privately if you'd prefer) The rest is long and probably discouraging, but hang in there.. >Oh, yeah, I forgot to say why just printf'ing won't work. I've got 40 >different messages to print, some have numbers in them, some display the >time, some display temperatures, some don't. It would be simple if they >were all like: > >"10:01 AM System ON" > >But some of them are also like: > >"Soup Temperature 24510F" or >"Error! You Bozo, shut off the power!" or >"Call 1-800-IMA-DUMMY for help" and so on. * Why can't you let the output device 'concatenate', and you just worry about sending them out in the correct sequence? Don't forget that array names (and that's all that strings are in C, unlike some more sophisticated languages) are pointers.. so if you write: char my_string[]="Hello, world\n"; then my_string is already a pointer to char >That's why I am thinking that concatenating a string would be the right >approach. So far my efforts with STRCAT have produced nil for output. For >instance the simple code: /* allocate memory for the strings and initialize them */ #define BUF_SIZE 20 char string1[BUF_SIZE]=""; /* make them globals */ char string2[2]=""; int main(void) { do { puts(string1); /* appends a newline */ delay_ms(1000); strcpy(string2,"A"); strcat(string1,string2); } while(strlen(string1) < (BUF_SIZE - 1)); /* let's not crash and burn */ return 0; /* stay with the ANSI program */ } Note: without the last line's conditional the program will invoke the dreaded Undefined Behavior very quickly... because string has but 20 bytes allocated. That means it can hold at most 19 characters plus the terminating null. Since we concatenate before testing the loop and *then* print, we can print at most BUF_SIZE - 2 characters. If you want to write a number into a string, use sprintf, which accepts the same formating as printf. sprintf(string1,"Temperature: %d F"); Note that string1 must be long enough to accept the largest possible number of characters or Bad Things will happen, as the memory is not dynamically allocated. BTW, usually you don't really want to be doing string manipulation like this with the small micros if you can avoid it, there is not much RAM.. so it is better to spit out the pieces in the order you want and let the output device buffer/concatenate/whatever them. Avoiding printf/sprintf is also nice, but with what you are doing, probably not practical. > DO{ > puts(*string1); > delay_ms(1000); > > strcpy(string2, "A"); > strcat(*string1, *string2); // concatenate string1 and 'A' > > }WHILE(TRUE); > >which I imagined might print "A" then "AA" then "AAA" then "AAAA" etc just >prints a CR-LF over and over. Phooey. > >> > >> > STRCAT(string1, Hours); // of course, Hours is an INT, not a string, >how to >> > convert to a string? Use sprintf: sprintf(string1, "%02d", Hours); >> > STRCAT(string1, ':'); // blinky colon mm.. ':' is not a string, it is a char! Try ":" Also STRCAT() is not a C library function (but strcat() is..) >> > STRCAT(string1, Minutes); // minutes, also still an INT not a string ??? Use sprintf. >> > STRCAT(string1, 'PM'); // does this work with a buncha letters? Syntax error.. use "PM", which generates a null terminated string literal. The 'X' construct is limited to characters such as 'A' or '\n'. >> > Printf(*string1); // ?????????? Printf() is not a C library function, but printf() is, and this is wrong. You need something like this.. printf("%s", string1); I'd probably do the whole thing in one line like this: printf("%02d:%02d %s\n", Hours, Minutes, am_pm_flag ? "AM" : "PM"); but that would probably just confuse the hell out of you at this point. >> > Any suggestions are welcome I suggest you get a good book on C, and a PC C compiler (an old Borland one will do) with good watch windows and so on and play with it. It's too frustrating trying to learn C with a microcontroller setup. IMHO. Your learning will increase with every mistake, so you want to make mistakes (and fix them) as quickly as possible. Best regards, =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Spehro Pefhany --"it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com Contributions invited->The AVR-gcc FAQ is at: http://www.bluecollarlinux.com =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu