C ++を使用して、fgetsを使用してテキストファイルをchar配列に読み込んでいます。次に、この配列内のすべての要素のインデックスを取得します。つまり、line [0] = 0.54 3.25 1.27 9.85、次に行のすべての要素を返します。別の配列の[0]、つまりreadElement [0]=0.54。私のtext.txtファイルの形式は次のとおりです。0.543.251.279.85 1.23 4.752.913.23これが私が書いたコードです。
char line[200]; /* declare a char array */
char* readElement [];
read = fopen("text.txt", "r");
while (fgets(line,200,read)!=NULL){ /* reads one line at a time*/
printf ("%s print line\n",line[0]); // this generates an error
readElement [n]= strtok(line, " "); // Splits spaces between words in line
while (readElement [1] != NULL)
{
printf ("%s\n", readElement [1]); // this print the entire line not only element 1
readElement [1] = strtok (NULL, " ");
}
n++;
}
ありがとう