【问题标题】:format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Wformat] in fprintf格式“%s”需要“char *”类型的参数,但参数 3 在 fprintf 中具有“int”类型 [-Wformat]
【发布时间】:2012-11-18 12:48:32
【问题描述】:

我有以下方法内容:

FILE *file;
file = fopen("customers.dat", "w");
PList *list;
list = &customers;
fprintf(file, "%s", *(list->person.name));

在 fprintf 行给出错误::

format '%s' expects argument of type 'char *', but argument 3 has type 'int' [-Wformat]

我有以下结构:

PList:

typedef struct PList{
    Person person;
    struct PList *nextPerson;  //  set to NULL by default <<<<<
}PList;

人:

typedef struct Person{
    char name[100]; // Left as "" if empty Person
    PersonID ID;
    float amountOwed;
}Person;

人名:

typedef struct PersonID{
    char letter;
    int number; // 7 digits
}PersonID;

【问题讨论】:

    标签: c types arguments printf


    【解决方案1】:

    删除*

    fprintf(file, "%s", *(list->person.name));
                        ^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      相关资源
      最近更新 更多