Hello,
I am newbie in C. I stored strings in array. (I know that string itself is an array. ) There is error when I compile and run the program. But I need to be sure that the following idea is correct or not since I dont want to meet unnecessary problems later.
I'd like push strings onto the stack_array using a loop or function call.
For example, it will look like:
Code:
stack[0] = " This is first line";
stack[1] = " This is second line";
.....
.....
.....
stack[i] = " This is last line";
Code:
// global variable declaration
const int depth = 30;
char* Stack[depth ];
int index= 0
function Add_data_to_stack (char *data, int data_length)
{
// memory allocation for stack[index] happened here
strncpy(Stack[index],data,data_length); // copy data to stack[index]
Stack[counter][len] = '\0'; // adding zero terminated character
index++;
// release memory allocation here ( free () )
}