Advertisement

06.06.2008 at 10:41AM PDT, ID: 23464486
[x]
Attachment Details

Freeing Pointer to Char Pointers

Asked by Kanivorous in C Programming Language

Tags: C

Hi I have a pointer to a wchar pointer which first gets allocated the size of the array:

wchar_t** wargv;
wargv = (wchar_t**)malloc(argc);

Then for every char pointer that it points to, allocates a certain amount of bytes to each char pointer. When freeing this, do I just need to free wargv? or do I need to free every char pointer that wargv points? or both (in what order)?

for(int k=0; k<argc; k++)
{
      sizeArgv = strlen(argv[k]) * sizeof(wchar_t);
      wargv[k] = (wchar_t*)malloc(sizeArgv);
      mbstowcs(wargv[k], argv[k], sizeArgv);
}

Thank you!Start Free Trial
 
Loading Advertisement...
 
[+][-]06.06.2008 at 12:07PM PDT, ID: 21731893

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C Programming Language
Tags: C
Sign Up Now!
Solution Provided By: Kdo
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628