fsacnfに関するmsdnの説明を見て、コードを変更しようとしました..それは惨事であり、それがどのように機能するかわかりません..たとえば、次の情報を持つファイルxがある場合: "string" 7 3.13 ' x' scanf("%s",&string_input) と書くと、文字列が保存され、次の行に移動しますか? →7まで?そして、私は次のように書きます: char test; fscanf("%c" , &test) -- 'x' にジャンプするか、7 を取り、ASCII 値に変換しますか?
ここに私が試したコードと出力があります:
#include <stdio.h>
FILE *stream;
int main( void )
{
long l;
float fp,fp1;
char s[81];
char c,t;
stream = fopen( "fscanf.out", "w+" );
if( stream == NULL )
printf( "The file fscanf.out was not opened\n" );
else
{
fprintf( stream, "%s %d %c%f%ld%f%c", "a-string",48,'y', 5.15,
65000, 3.14159, 'x' );
// Security caution!
// Beware loading data from a file without confirming its size,
// as it may lead to a buffer overrun situation.
/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );
/* Read data back from file: */
fscanf( stream, "%s", s );
fscanf( stream, "%c", &t );
fscanf( stream, "%c", &c );
fscanf( stream, "%f", &fp );
fscanf( stream, "%f", &fp1 );
fscanf( stream, "%ld", &l );
printf( "%s\n", s );
printf("%c\n" , t);
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );
printf("f\n",fp1);
getchar();
fclose( stream );
}
}
これは出力です:
文字列 -858553460 8.000000 4 へ
理由がわからない
ありがとう!!