포인터 배열 생성 질문
글쓴이: 익명 사용자 / 작성시간: 금, 2019/09/27 - 12:15오후
포인터 배열을 만들어서 csv에 있는 문자열을 구분자를 기준으로 분리해서 집어넣으려고 했는데 실행이 안되네요. 어떻게 해야 포인터 배열을 만들어서 문자열을 넣을 수 있을까요...
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
struct User{
char name[30];
char number[15];
};
int main( )
{
int pFile;
pFile = open( "test.csv", O_RDWR | O_APPEND);
int location = lseek(pFile, 0, SEEK_END);
char *buf;
buf = (char*)malloc(location);
lseek(pFile, 0, SEEK_SET);
read(pFile, buf, location);
char *ptr = strtok(buf, "\n");
int i=0;
char* poin[location] = {NULL, };
while (ptr != NULL)
{
poin[i] = ptr;
printf("%s\n",(*poin)[i]);
ptr = strtok(NULL, "\n");
i++;
}
free(buf);
close(pFile);
return 0;
}Forums:

댓글 달기