尝试扫描并打印结构中的字符串

时间:2021-03-04 00:19:06

标签: c string struct

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>

typedef struct veiculos
{
    char modelo[20];
    char marca[20];
    int ano;
    int preco;
}Vei;

int main()
{
    Vei v1, v2;

    scanf("%s", &v1.modelo);
    scanf("%s", &v1.marca);
    scanf("%d", &v1.ano);
    scanf("%d", &v1.preco);

    scanf("%s", &v2.modelo);
    scanf("%s", &v2.marca);
    scanf("%d", &v2.ano);
    scanf("%d", &v2.preco);

    if(v1.ano == v2.ano)
    {
        if(v1.preco < v2.preco)
        {
            printf("%s %s", v1.marca, v1.modelo);
        }
        else printf("%s %s", v2.marca, v2.modelo);
    }
    if(v1.ano < v2.ano)
    {
        printf("%s %s", v1.marca, v1.modelo);
    }
    else printf("%s %s", v2.marca, v2.modelo);
}

我总是收到这个错误,尝试了很多东西。

In function 'int main()':
warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[20]' [-Wformat=]
   19 |     scanf("%s", &v1.modelo);

感谢您的帮助。

0 个答案:

没有答案
相关问题