69,371
社区成员
发帖
与我相关
我的任务
分享
#define MAX_PLANET 500
int coor[MAX_PLANET][3] = {{1,2,6},{5,2,6},{3,13,23},{7,8,1},{4,5,2}};
#include <stdio.h>
#include <stdlib.h>
#define MAX_PLANET 500
int main()
{
int coor[MAX_PLANET][3] = {0};
FILE *fp = fopen("in.txt", "r");
if(!fp)
{
printf("error\n");
exit(1);
}
for(int i=0;i<MAX_PLANET;i++)
{
if(fscanf(fp, "%d %d %d", &coor[i][0], &coor[i][1], &coor[i][2])==EOF)
break;
}
for(int j=0;j<i;j++)
printf("%d %d %d\n", coor[j][0], coor[j][1], coor[j][2]);
fclose(fp);
return 0;
}
1 2 6
5 2 6
3 13 23
7 8 1
4 5 2
1 2 6
5 2 6
3 13 23
7 8 1
4 5 2
Press any key to continue
#define MAX_PLANET 500
int coor[MAX_PLANET][3] = {{1,2,6},{5,2,6},{3,13,23},{7,8,1},{4,5,2}};
int i;
for(i=0;i<=MAX_PLANET;i++)
{
fscanf("%d %d %d %d",&coor[i][0],*coor[i][1],&coor[i][2],&coor[i][3])
}
#include <stdio.h>
FILE *stream;
void main( void )
{
long l;
float fp;
char s[81];
char c;
stream = fopen( "fscanf.out", "w+" );
if( stream == NULL )
printf( "The file fscanf.out was not opened\n" );
else
{
fprintf( stream, "%s %ld %f%c", "a-string",
65000, 3.14159, 'x' );
/* Set pointer to beginning of file: */
fseek( stream, 0L, SEEK_SET );
/* Read data back from file: */
fscanf( stream, "%s", s );
fscanf( stream, "%ld", &l );
fscanf( stream, "%f", &fp );
fscanf( stream, "%c", &c );
/* Output data read: */
printf( "%s\n", s );
printf( "%ld\n", l );
printf( "%f\n", fp );
printf( "%c\n", c );
fclose( stream );
}
}
Output
a-string
65000
3.141590
x