结构体程序错误

liyi54188 liyi54188 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
i请问下我程序为什么会报如下错误啊,应如何改正啊,谢谢指教!
threadexstatus.c: In function ‘thfn4’:
threadexstatus.c:56:4: error: request for member ‘b’ in something not a structure or union
threadexstatus.c:57:4: error: request for member ‘c’ in something not a structure or union
threadexstatus.c:82:75: error: expected expression before ‘)’ token
threadexstatus.c:115:71: error: expected ‘{’ before ‘*’ token
threadexstatus.c:115:77: error: request for member ‘c’ in something not a structure or union
threadexstatus.c:131:52: error: expected ‘)’ before ‘res’
threadexstatus.c:131:57: error: expected ‘)’ before ‘->’ token


1 #include <unistd.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <pthread.h>
5
6 struct a
7 {
8 int b;
9 int c;
10 };
11
12 void * thfn1(void * arg)
13 {
14 struct a r1;
15
16 printf("the first\n");
17
18 r1.b = 10;
19 r1.c = 11;
20
21 return (void *)(&r1);
22 }
23
24 void * thfn2(void * arg)
25 {
26 struct a * r2;
27

28 printf("the second one \n");
29
30 r2 = (struct a *)malloc(sizeof(struct a));
31
32 r2 -> b = 10;
33 r2 -> c = 11;
34
35 return (void *)(&r2);
36 }
37
38 void * thfn3(void * arg)
39 {
40 struct a r3;
41
42 printf("the third one\n");
43
44 r3.b = 10;
45 r3.c = 11;
46
47 return (void *)(&r3);
48 }
49
50 void * thfn4(void * arg)
51 {
52 struct a * r4 = (struct a * )arg;
53
54 printf("the fourth one\n");
55
56 r4.b = 10;
57 r4.c = 11;
58
59 return (void *)(&r4);
60 }
61
62 int main(void)
63 {
64 int err;
65 void * res;
66 pthread_t tid1, tid2, tid3, tid4;
67
68 err = pthread_create(&tid1, NULL, thfn1, NULL);
69 if(err != 0)
70 {
71 printf("can not create thread %s\n", strerror(err));
72 exit(1);
73 }
74
75 err = pthread_join(tid1, &res);
76 if(err != 0)
77 {
78 printf("can not create thread %s\n", strerror(err));
79 exit(1);
80 }
81
82 printf("result from thfn1: %d, %d\n", ((struct a *)res)->b, ((struct a *))res->c);
83
84 err = pthread_create(&tid2, NULL, thfn2, NULL);
85 if(err != 0)
86 {
87 printf("can not create thread %s\n", strerror(err));
88 exit(1);
89 }
90
91 err = pthread_join(tid2, &res);
92 if(err != 0)
93 {
94 printf("can not create thread %s\n", strerror(err));
95 exit(1);
96 }
97
98 printf("result from thfn2: %d, %d\n", ((struct a *)res)->b, ((struct a *)res)->c);
99 free(res);
100
101 err = pthread_create(&tid3, NULL, thfn3, NULL);
102 if(err != 0)
103 {
104 printf("can not create thread %s\n", strerror(err));
105 exit(1);
106 }
107
108 err = pthread_join(tid3, &res);
109 if(err != 0)
110 {
111 printf("can not create thread %s\n", strerror(err));
112 exit(1);
113 }
114
115 printf("result from thfn3: %d, %d\n", ((struct a *)res)->b, ((struct *)res)->c);
116
117 err = pthread_create(&tid4, NULL, thfn4, NULL);
118 if(err != 0)
119 {
120 printf("can not create thread %s\n", strerror(err));
121 exit(1);
122 }
123
124 err = pthread_join(tid4, &res);
125 if(err != 0)
126 {
127 printf("can not create thread %s\n", strerror(err));
128 exit(1);
129 }
130
131 printf("result from thfn4: %d, %d\n", (struct a *(res))->b, (struct a *(res))->c);
132
133 return 0;
134 }
65,1-4 28%
...全文

相关推荐

大一C语言程序设计A课程作业与上机实验集合_包含基础语法练习数组操作函数编写指针应用结构体实践文件读写算法实现调试技巧代码优化编程思维训练问题解决案例错误处理.zip

最后,错误处理部分,主要讲解如何在C语言中处理运行时错误和异常情况,这对于编写健壮的程序代码至关重要。这篇文章集合了C语言编程学习中的各个方面,是一份非常全面的学习资源,对初学者来说是一份宝贵的财富。

2501_92227435

c语言的课件 有概述,算法,数据类型,简单程序,选择,循环,数组,函数,预处理,指针,结构体,位运算,文件和常见错误 徐州师范大学计算机科学与技术学院

**结构体**:结构体允许将不同类型的数据组合成一个单一的结构,便于管理复杂的数据结构。12.

xushuimei

实验1菜单及结构体数组 (1).zip

循环处理:在用户选择退出之前,程序将不断重复以上步骤。在实验中,你可能会遇到以下几个关键点:- 输入处理:确保正确处理用户的输入,防止非法输入导致程序错误。

肖大神cherry

C程序设计第三版常见错误ppt课件.ppt

- 结构体类型与结构体变量:结构体类型不能直接赋值,只能通过结构体变量完成。4. **运行错误**: - 文件操作错误:忘记打开文件或打开方式不正确。

xinkai1688

linux下can驱动及应用程序实现

**错误处理**:CAN总线有错误帧的概念,驱动需要能检测并处理错误状态,如位错误、帧错误等。二、应用程序开发1.

孤独的小丑
评论 8
收藏 已收藏
分享
返回顶部
liyi54188
Linux/Unix社区 23,224 成员 74,535 内容