tags:

views:

124

answers:

3
+1  Q: 

segmentation fault

       int num_arrays;
       char *p[20];
       char tempc;       
       int i=0;
       do
       { p[i]=malloc(sizeof(int));
        scanf("%s",p[i]);
        tempc=*p[i];
        ++i;
        }while(tempc=='x');
        num_arrays=atoi(p[0]);

When i write num_arrays=atoi(..),gcc give me segmentation fault or memory stack is exceeded, I don't understand why it behaves like that can anyone explain, why?

+4  A: 

You are not allocating memory for your strings. (Edit: Now you are)

You may also want to make sure you are not doing more than 20 iterations since your array of char* only has 20 elements.

Also assuming sizeof(int) == 4, your strings must not be greater than 4 chars as you have now and 1 of those needs to be a null termination. You may want to allocate more room for those input strings.

Brian R. Bondy
+4  A: 
Péter Török
//while writing that question , i forget but in my real code ,i have allocated memeory
gcc
@gcc, see my update. I recommend you to double check your code before posting in the future :-)
Péter Török
A: 

sri

i am akshath,i am BE graduate,and i have knowledge on C,C++,SAP-ABAP, and also microprocessor 8085,86,and micro controller 8051. And i am intrestiing to work with this Free source org.. so please help me to take the account and how to do the work here

akshath