View Single Post
Old 06-10-2005, 06:54 PM   #1 (permalink)
MicroBlaze
Registered User
 
Join Date: Jun 2005
Posts: 2
MicroBlaze is on a distinguished road
Question Help Adding a CHAR to the end of a STRING

Code:
//====================================================

int main (void) {

   printf("------------------------------------------------\r\n");
   printf("-- Entering main() --\r\n");
   printf("------------------------------------------------\r\n");


  /* Help... after 3 hours I need some help...  I want to take a char
   and add it to the end of a string.  and then be able to print the 
   new string with a standard printf.  Here is a snip of the code I 
   can't get to work... */

// 16 char string that will later be sent to a 2x16 LCD display 
  char LCDString[16] = "Switch = "; 

  char dipSwitch1;
  char dipSwitch2;  
  dipSwitch1 = '6';
  dipSwitch2 = '3';
  printf("the value of the dipSwitches are %c and %c \r\n", dipSwitch1,dipSwitch2);
// This does print the text "the value of charOnes is 6"
// Now I want to take charOnes and add it to the end of the string LCDString
// strcat only seems to work when I has 2 text strings like the following
  char str[80];
  strcpy (str,"strings  ");
  strcat (str,"have been ");
  strcat (str,"concatenated.");
  printf("%s \r\n",str);
/* But what I want is something like strcat (LCDString, charOnes)... 
  but this does not work.  charOnes ends up as odd charachers 
  like "¨°0" or some other unprintable thing... and it seems to 
  change based on the number of lines in my code... so I think I'm 
  getting some pointer or address of what I really want... help  */
  char str2[16];
  strcpy (str2,"Switch =  ");
  strcat (str2,dipSwitch1);
  printf("%s \r\n",str2);
// I want the string to be "Switch = 6"
  strcat (str2,dipSwitch2);
  printf("%s \r\n",str2);
// now I want it to be I want the string to be "Switch = 63"

   printf("------------------------------------------------\r\n");
   print("-- Exiting main() --\r\n");
   printf("------------------------------------------------\r\n");
   return 0;
}

Last edited by redhead; 06-11-2005 at 07:04 AM. Reason: added [code][/code] tags
MicroBlaze is offline   Reply With Quote