다음 예제 1과 2의 차이점을 알고 싶습니다.
strdup를 쓰면 메모리를 해제 시켜야 하는 점이 있는데 굳이 strdup을 썼다면 그 이유가 무엇일까요?
예제1 :
names = strdup("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z");
printf("input: %s\n", names);
count = unique_name_vector(names, ',', vector, 20);
printf("count: %d\n", count);
printf("output:");
for (i = 0; i < count; ++i)
printf(" %s", vector[i]);
printf("\n");
free(names);
예제 2:
*names = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
printf("input: %s\n", names);