Skip to content

Instantly share code, notes, and snippets.

@hemantborole
Created January 6, 2010 01:33
Show Gist options
  • Save hemantborole/269920 to your computer and use it in GitHub Desktop.
Save hemantborole/269920 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 1024
int main() {
int i =0;
char env[][MAX] = {"one", "two", "three" };
char **newenv = NULL;
char add[][MAX] = {"four","5", "6"};
newenv = (char**) calloc( sizeof(char), 3*MAX);
for( i=0; i < 3; i++ ) {
newenv[i] = (char *) malloc(MAX * sizeof(char));
strcpy(newenv[i], env[i]);
}
for( i=3; i < 6; i++ ) {
newenv[i] = (char *) malloc(MAX * sizeof(char));
strcpy(newenv[i], add[i-3]);
}
for( i=0; i < 6; i++ ) {
printf("New array has %s\n", newenv[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment