Advertisement

more: c++ char data type

Started by September 17, 2002 10:20 AM
3 comments, last by dario_s 22 years, 5 months ago
Ok, I still have some problems with this... I have the function:
  
void ConsoleAddChar(char *char_to_add)
{
  char *temp[7];
  strcat(temp[7], char_to_add);	// Append new character

}
  
It's supposed to add one character to the temp "string"... The temp string consists of 7 strings: temp = {string0, string1, string2, ..., string6} But I cant get it to work... I think its because temp is a pointer and I dont have any rights to write data to a pointer right? How should I solve this? I NEED to keep the *temp[7] structure All I get is these errors: Run-Time Check Failure #3 - The variable 'temp' is being used without being defined. Unhandled exception at 0x00418c87 in blabla.exe: 0xC0000005: Access violation writing location 0x00433089. [edited by - dario_s on September 17, 2002 11:23:50 AM]
You haven''t allocated any space yet for the strings. You''ve created an array of 7 char pointers, but still need to go through each of those pointers and allocate space for each:


  for ( int a = 0; a < 7; a++ )    temp [ a ] = new char [ 256 ];  


This''ll create space for 7 strings each of up to 256 characters.

Also, remember that temp is going to be lost at end of the function, so you''re going to need to have some way to pass those strings back out of the function.
Advertisement
what are you talking about??

I have no heatsink problems... This is program code!
quote:
Original post by dario_s
what are you talking about??

I have no heatsink problems... This is program code!

There are problems with the forums right now. Your thread is elsewhere.


Don''t listen to me. I''ve had too much coffee.

This topic is closed to new replies.

Advertisement