hi there i am super confused, i am writing a program to launch processess and on my travels i was getting some wierd results from command line arguments that i was attempting to parse ( none of that here ) but the wierdest thing ever happens below....???
i have removed all of the other code, all other functions etc i have a blank utility.c folder ( where i keep all functions that i call in main, i deleted everything except for 1 line comment),i have removed any function calls from main .... what you see below is all that is running ??
note that there is no malloc for the pointer char **progNameAndArgs1;, nor is there a malloc for an element within that ie progNameAndArgs1[0] = malloc ....
so my question is how do i get the outputCode:int main(int argc, char *argv[]) { int test1 = 0; int numberOfProgs; int i =0; char **progNameAndArgs1; char **progNames; char *progNames2[2]; char **progNameAndArgs2 = malloc(sizeof(char*)*(2)); printf(" main progNameAndArgs1 %s \n ",progNameAndArgs1[0]); printf(" main progNameAndArgs1 %s \n ",progNameAndArgs1[1]);
when i pass ./driver ./foo at the command line ????Code:main progNameAndArgs1 ./driver main progNameAndArgs1 ./foo
from my thinking
1 . char **progNameAndArgs1 is pointing to the same memory as argv ??? is this standard??
couple of questions
1 when a program completes, and then i run it again am i accessing the same area of memory ??
2 if i create a string array and add an entry
if i do the right thing then when i finish up i free(stringArray) or the individual elements....Code:char **stringArray = malloc(sizeOf(char*)*2) stringArray[0] = malloc(sizeof(char)*5) strcpy(stringArray[0],"ted");
but if i don't free it up is it left somehow in memory ??
so if i ran my program for a 2nd time but changed the code to
and then printed stringArray[0] would i get ted again ?????Code:char **stringArray ; printf(" %s \n",stringArray[0] )



LinkBack URL
About LinkBacks



