如何使用指针在C中打印带有结构的变量?

如何使用指针在C中打印带有结构的变量?,c,pointers,C,Pointers,我的练习是使用一个结构来初始化值,然后打印它们(听起来很简单),但是我们必须使用指针*p,而不是使用这个结构来打印它们。我知道这可能有一个非常简单的答案,但帮助将不胜感激 #include <stdio.h> #include <string.h> struct info { int total; char *str; }; int main() { struct info s, *p = &s; s.total = 50;

我的练习是使用一个结构来初始化值,然后打印它们(听起来很简单),但是我们必须使用指针*p,而不是使用这个结构来打印它们。我知道这可能有一个非常简单的答案,但帮助将不胜感激

#include <stdio.h>
#include <string.h>

struct info
{
    int total;
    char *str;
};

int main()
{

    struct info s, *p = &s;

    s.total = 50;
    s.str = "hello";

    printf("Info total: %i\n", s.total);
    printf("Info *str: %s\n", s.str);

    return 0;
}
#包括
#包括
结构信息
{
整数合计;
char*str;
};
int main()
{
结构信息s,*p=&s;
s、 总数=50;
s、 str=“你好”;
printf(“信息总数:%i\n”,s.total);
printf(“Info*str:%s\n”,s.str);
返回0;
}
s.total p->total或(*p).total

谢谢大家的回答

你听说过吗?你读过C语言书中关于结构的段落吗?
s.total
p->total
(*p)。total
谢谢你myaut和BLUEPIXY!我现在已经开始工作了。哎呀,今年我们没有一本模块书,只有讲师写的一本大笔记,没有提到这个箭头操作符。
s.total <=> p->total or (*p).total