c-扫描到结构不起作用



我有这个函数,需要获取结构的坐标。这些是结构:
//---------结构----------------

typedef struct coordinates  
{
    int x_l;
    int y_l;
    int x_r;
    int y_r;
} Coordinates;
typedef struct field 
{
    char Id;
    Coordinates location;
    int area;
    int price;
} Field;

这就是功能:

Field GetFieldFromUser(int cptr,Field *pf1)
{       
    //Field *pf
    int i=0;
    printf("nPlease enter information for your new field:n");
    printf("the Id of the field is 5 digit num between 00000-99999:n");
    printf("The Id of the Field given Automatic by the systemn");

    pf1->Id= 0000+cptr;
    printf("nThis is the ID for the new field: ");
    printf("id = %05dn",pf1->Id);
    printf("nPlease enter the coordinates of the top left of the field (press ' ' between the digits)n");
    scanf("%d %d",pf1->location.x_l,pf1->location.y_l);
    fflush(stdin);
    printf("Please enter the coordinates of the lower right of the field (press ' ' between the digits)n");
    scanf("%d %d",pf1->location.x_r,pf1->location.y_r);
    return *pf1;
}

现在,在扫描位置时,编译器把我赶了出去,我不知道为什么

有什么建议吗?

scanf("%d %d",pf1->location.x_l,pf1->location.y_l);

应该是

scanf("%d %d",&(pf1->location.x_l), &(pf1->location.y_l));

下一次扫描的逻辑相同。scanf需要它可以写入的地址。您正在向它传递值(可能是未初始化的值)。所以它试图写入某个未知的内存位置。

相关内容

  • 没有找到相关文章

最新更新