小编Cod*_*der的帖子

数组不能打印正确的值

我正在尝试从文本文件中读取数字并将其存储到数组中.当我尝试读取数组中的数字时,输出略微偏离.这是我的代码:

struct point{
    double x[7];
    double y[7];
}point;

int main()
{
    FILE *fp;
    fp = fopen("data_2.txt", "r");
    struct point points;
    int len = 8;
    int i = 0;
    int j = 0;
    int k = 0;
    double a = 0;
    double b = 0;
    double c = 0;
    double total = 0;
    int left=0;
    int right=0;
    int line = 0;
    for (i=0;i<len;i++)
    {
        fscanf(fp, "%lf %lf", &points.x[i],&points.y[i]);
    }
    for(i = 0; i < len;i++)
        printf("looking at point %.2f %.2f\n",points.x[i],points.y[i]);

    return(0); …
Run Code Online (Sandbox Code Playgroud)

c arrays

6
推荐指数
1
解决办法
105
查看次数

标签 统计

arrays ×1

c ×1