私はファイルから並列配列にスキャンしています。 文字列は正常にスキャンされますが、intとfloatは正しくスキャンされません。 ここで何がうまくいかないのですか? Num、human、およびcoolは、main関数で宣言された配列です。文字列とintをファイルからC言語の配列にスキャン
hello.txtのレコードの例: Angela, Merkel, 50, 10, 9.1
void read(int *lines, char first[ENTRY][FIRST], char last[ENTRY][LAST], int *num, int *human, float *cool)
{
FILE *ifile;
int i;
ifile = fopen("hello.txt", "r");
fscanf(ifile, "%[^,] %*c %[^,] %*c %d %*c %d %*c %f", first[0], last[0], &num[0], &human[0], &cool[0]);
printf("%s", first[0]);
printf("%s\n", last[0]);
printf("%d\n", num[0]);
printf("%d\n", human[0]);
printf("%f", cool[0]);
fclose(ifile);
}
まず、関数fscanf 'の戻り値をチェック()' ... –
ショー 'hello.txt'、定義変数とどのようにこれを呼び出します。 – BLUEPIXY
@ user9012ここで十分な質問を投稿できますか?私たちは大いに助けません – Sathish