我有一个简单的程序,它读入位置和速度列表,尽管它没有编译。我只是想向用户询问位置和速度文件的名称,然后在 main() 中输出数组。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define loop(idx,last) for (idx = 0; idx < last ; idx++)
float readinput (char *posfile, char *velfile);
int main (void)
{
char posfile[100],velfile[100];
float pos[10000][3], vel[10000][3];
printf( "What is the name of your positions file (x y z): " );
scanf( "%s", &posfile );
printf( "What is the name of your velocity file (vx vy vz): " );
scanf( "%s", &velfile );
pos = readinput(posfile,velfile);
return 0;
}
float readinput (char *posfile, char *velfile)
{
float pos[10000][3], vel[10000][3];
float x,y,z;
float vx,vy,vz;
int i;
char line[256];
FILE *files;
files = fopen(posfile, "r");
loop(i,10000){
fscanf(files, "\n%f %f %f\t", &x, &y, &z);
pos[i][0] = x;
pos[i][1] = y;
pos[i][2] = z;
printf("\n%f %f %f\t",x,y,z);
}
fclose(files);
files = fopen(velfile, "r");
loop(i,10000){
fscanf(files, "\n%f %f %f\t", &vx, &vy, &vz);
vel[i][0] = vx;
vel[i][1] = vy;
vel[i][2] = vz;
printf("\n%f %f %f\t",vx,vy,vz);
}
fclose(files);
return pos;
}
我很抱歉,这是我的第一个程序。
main.c: In function 'main':
main.c:18:5: error: incompatible types when assigning to type 'float[10000][3]' from type 'float'
pos = readinput(posfile,velfile);
^
main.c: In function 'readinput':
main.c:51:1: error: incompatible types when returning type 'float (*)[3]' but 'float' was expected
return pos;