Click here to Skip to main content
15,904,023 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow can i get file names dynamically? Pin
santhosh-padamatinti2-Jul-09 8:50
santhosh-padamatinti2-Jul-09 8:50 
QuestionRe: how can i get file names dynamically? Pin
Rajesh R Subramanian2-Jul-09 9:24
professionalRajesh R Subramanian2-Jul-09 9:24 
AnswerRe: how can i get file names dynamically? Pin
Stuart Dootson2-Jul-09 9:32
professionalStuart Dootson2-Jul-09 9:32 
AnswerRe: how can i get file names dynamically? Pin
Madhu Nair2-Jul-09 18:27
Madhu Nair2-Jul-09 18:27 
GeneralRe: how can i get file names dynamically? Pin
Stuart Dootson2-Jul-09 20:34
professionalStuart Dootson2-Jul-09 20:34 
JokeRe: how can i get file names dynamically? Pin
Rajesh R Subramanian2-Jul-09 22:00
professionalRajesh R Subramanian2-Jul-09 22:00 
JokeRe: how can i get file names dynamically? Pin
Stuart Dootson2-Jul-09 22:07
professionalStuart Dootson2-Jul-09 22:07 
GeneralRe: how can i get file names dynamically? Pin
Rajesh R Subramanian2-Jul-09 22:09
professionalRajesh R Subramanian2-Jul-09 22:09 
GeneralRe: how can i get file names dynamically? Pin
Stuart Dootson2-Jul-09 22:09
professionalStuart Dootson2-Jul-09 22:09 
QuestionRe: how can i get file names dynamically? Pin
David Crow2-Jul-09 9:34
David Crow2-Jul-09 9:34 
Questiondisable MFC dialog based Microsoft Web Browser showing context menu [modified] Pin
JACyo2-Jul-09 6:39
JACyo2-Jul-09 6:39 
AnswerRe: disable MFC dialog based Microsoft Web Browser showing context menu Pin
Stuart Dootson2-Jul-09 9:30
professionalStuart Dootson2-Jul-09 9:30 
GeneralRe: disable MFC dialog based Microsoft Web Browser showing context menu Pin
JACyo2-Jul-09 15:45
JACyo2-Jul-09 15:45 
GeneralRe: disable MFC dialog based Microsoft Web Browser showing context menu Pin
Stuart Dootson2-Jul-09 20:33
professionalStuart Dootson2-Jul-09 20:33 
Questionconvert vbscript to c++ Pin
Mogaambo2-Jul-09 6:26
Mogaambo2-Jul-09 6:26 
QuestionRe: convert vbscript to c++ Pin
led mike2-Jul-09 7:41
led mike2-Jul-09 7:41 
AnswerRe: convert vbscript to c++ Pin
Mogaambo2-Jul-09 8:32
Mogaambo2-Jul-09 8:32 
GeneralRe: convert vbscript to c++ Pin
led mike2-Jul-09 9:00
led mike2-Jul-09 9:00 
GeneralRe: convert vbscript to c++ Pin
Mogaambo2-Jul-09 9:06
Mogaambo2-Jul-09 9:06 
GeneralRe: convert vbscript to c++ Pin
Stuart Dootson2-Jul-09 9:26
professionalStuart Dootson2-Jul-09 9:26 
GeneralRe: convert vbscript to c++ Pin
Mogaambo2-Jul-09 9:28
Mogaambo2-Jul-09 9:28 
QuestionRe: convert vbscript to c++ Pin
David Crow2-Jul-09 9:31
David Crow2-Jul-09 9:31 
AnswerRe: convert vbscript to c++ Pin
Mogaambo2-Jul-09 9:39
Mogaambo2-Jul-09 9:39 
GeneralRe: convert vbscript to c++ Pin
Mogaambo2-Jul-09 9:41
Mogaambo2-Jul-09 9:41 
QuestionDynamic char Array Pin
jlgeris2-Jul-09 5:38
jlgeris2-Jul-09 5:38 
Essentially, I'm reading some names from a text file, and I need to allocate the array at runtime. I'm missing something regarding the allocation of each individual name. After I copy the first name into the array slot, it fills up every spot in the array with the first value. After the loop finishes I have an array with [count] copies of the initial value I read from the file.

I'm using the StreamReader class in other places in the program so that's why I'm marshaling the string to a char*. Maybe not the ideal solution, but I believe the problem is separate from that.

char **temp=NULL;
my_malloc((void**)&temp,count*sizeof(char*));

StreamReader^ din = File::OpenText(fileName);
String^ str;

while ((str = din->ReadLine()) != nullptr)
{			
  char* x = (char*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(str).ToPointer();
  my_malloc((void**)&temp[count],strlen(x)*sizeof(char)+1);  //i imagine the problem is here
  strcpy(temp[count],x);				     //or here
  System::Runtime::InteropServices::Marshal::FreeHGlobal((IntPtr)x);
  count++;
}



The my_malloc function is just a wrapper around free() and malloc().


Thanks for the help.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.