Hi,
I have the following code that I run and compile successfully on Visual Studio 2008 using C, but the problem is when the program tries to run the first free call it just hangs there and does nothing :S. In GNU Linux the program runs fine but windows shows a very strange behavior with this.
here is the code
Create a 2D array dynamically
Now we later on we will the array:
And finally this is the free function used which shows the strange behavious on windows (it stops in the first iteration of the free function):
The code is corrent and should run fine (it does on Linux using gcc but windows is ><)
Waiting for your responces!
I have the following code that I run and compile successfully on Visual Studio 2008 using C, but the problem is when the program tries to run the first free call it just hangs there and does nothing :S. In GNU Linux the program runs fine but windows shows a very strange behavior with this.
here is the code
Create a 2D array dynamically
Code:
// now that we have our choice, let's create our dynamic string pointer // array using the specified size char **sptrTable = (char**)calloc( (tabSize+1), sizeof(int) ); // check for valid allocation if( sptrTable == NULL ) { fprintf( stdout,"\nNo memory was allocated due to insufficient memory, please free up some memory and try again\nThe program will now exit\n"); return ERROR_CODE; } // set our exit code for the allocation size sptrTable[tabSize] = (char*)calloc( 1, sizeof(int) ); sptrTable[tabSize][0] = ALLOCATION_LIMIT;
Code:
while ( allocCheck ) { // create the string in the table and // check if the memory was allocated ok if ( (ptr[index] = (char *)calloc( strlen(buff), sizeof(char) ) ) == NULL ) { return ERROR_CODE; } // advance the pointer to next value ptr[index++]; // check for allocation limit if ( ptr[index] != NULL && ptr[index][0] == (ALLOCATION_LIMIT) ) { allocCheck = TRUE; } }
Code:
void freeChunks( int **ptr, int tabSize ) { int index = 0; int i = 0; // free the columns while( index <= tabSize && ( ptr[index] != NULL) ) { free( ptr[index] ); index++; } // free the rows free( ptr ); }
Waiting for your responces!
Comment