【问题标题】:lvalue required as increment operand using pointers and struct需要左值作为使用指针和结构的增量操作数
【发布时间】:2016-10-16 15:01:19
【问题描述】:

我可以知道有什么问题吗?

for ( ; *line[0]; ++line[0], ++p->title) p->title = tolower(*line[0]);

p 是 struct,title 是 char 指针,line 是 string/char 指针

typedef struct p{
    char *title;
} p;

我正在尝试将字符串转换为全部小写。

【问题讨论】:

  • 您应该为p 发布struct 的声明。 p->surname 是什么?
  • @TedHopp 我已经发布了structp->surname 的声明是一个错字
  • 请发布来自编译器的确切错误消息。
  • @JohnBode lvalue required as increment operand for for ( ; *line[0]; ++line[0], ++p->title) p->title = tolower(*line[0]);

标签: c loops pointers for-loop


【解决方案1】:

您正在使用 p 作为指向结构的指针。如果你需要标题,你应该像这样使用句号运算符:

p.title

【讨论】:

  • 除了已经发布的一小段代码,p 甚至不是变量;这是一个 typedef 名称。
  • p是struct p的变量
  • @jon:不在您发布的代码中。在您提供的 sn-p 中,您创建了 p 作为类型 struct p 的 typedef 名称(同义词)。
猜你喜欢
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 2011-09-07
  • 2014-04-07
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多