int _tmain(int argc, _TCHAR* argv[]){ int n,i; char firstname[100]; char lastname [100]; char* list[100]; printf("How many (100 max)"); scanf("%d",&n); if(n>100) { exit(EXIT_FAILURE); } for(i=0; i < n ; i++){ printf("Enter first name\n"); scanf("%s",firstname); printf("Enter second name\n"); scanf("%s",lastname); list[i] = concatname(firstname,lastname); } printf("The full list of name is \n"); for(i=0; i <n ; i++){ printf ("%s\n",list[i]); } for(i=0;i<n;i++){ free(list[i]); } system("pause"); return 0; }
/* we know base to be well-formed, with a leading slash, no trailing slash */ char *resolvePath(char *base, char *ext, struct stat *info) { int first = 1; int linkdepth = 16; while (*ext) { int i, j, k; char *oldbase; for (i = 0; ext[i] == '/'; i++); for (j = i; ext[j] != 0 && ext[j] != '/'; j++); for (k = j; ext[k] == '/'; k++); /* empty string */ if (i == j) break; /* starts with / */ if (i != 0) base = "/"; oldbase = base; if (j - i == 1 && ext[i] == '.') { /* nothing to do */ } else if (j - i == 2 && ext[i] == '.' && ext[i+1] == '.') { /* back a directory */ base = dirname(base); } else { /* copy over one directory part */ base = concatname(base, substring(ext, i, j - i)); } ext += k; if (lstat(base, info) < 0) return NULL; if (S_ISLNK(info->st_mode)) { char *lnk = GC_MALLOC_ATOMIC(info->st_size + strlen(ext) + 2); assert(lnk != NULL); if (linkdepth <= 0 || readlink(base, lnk, info->st_size) < 0) return NULL; lnk[info->st_size] = 0; strcat(lnk, "/"); strcat(lnk, ext); ext = lnk; linkdepth--; base = oldbase; } else if (!S_ISDIR(info->st_mode)) { return NULL; } first = 0; } if (first) { if (lstat(base, info) < 0) return NULL; if (!S_ISDIR(info->st_mode)) return NULL; } return base; }