의 끝 부분에 빈 문자열을 읽기 :strtok를 내가처럼 보이는 파일에서 코드의 라인을 구문 분석 strtok를을 사용하여 아래의 내 코드에 라인
1023.89,863.19 1001.05,861.94 996.44,945.67 1019.28,946.92 1023.89,863.19
파일이 서로 다른 길이의 라인을 가지고 수 있듯이 나는 돈 fscanf를 사용하지 마십시오. 아래의 코드는 하나의 작은 결함을 제외하고는 작동합니다. 너무 많은 시간 동안 루프를 돌리고 널 빈 토큰을 다시 루핑하기 전에 긴 빈 문자열을 읽거나 while 루프를 빠져 나간다. 왜 이것이 될 수 있는지 모르겠습니다.
도움을 주시면 감사하겠습니다.
fgets(line, sizeof(line), some_file);
while ((line != OPC_NIL) {
token = strtok(line, "\t"); //Pull the string apart into tokens using the commas
input = op_prg_list_create();
while (token != NULL) {
test_token = strdup(token);
if (op_prg_list_size(input) == 0)
op_prg_list_insert(input,test_token,OPC_LISTPOS_HEAD);
else
op_prg_list_insert(input,test_token,OPC_LISTPOS_TAIL);
token = strtok (NULL, "\t");
}
fgets(line, sizeof(line), some_file);
}