Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
839 views
in Technique[技术] by (71.8m points)

c - error: expected ‘)’ before ‘*’ token

#include<stdio.h>
struct s_{
        int b;
}s;

int func1(s** ss){
        *ss->a = 10;
}
int func(s* t){
        func1(&t);
}
int main(){
        s a;
        func(&a);
        printf("
 a : %d 
",a.b);
        return 0;
}

Trying the sample program and getting an error with the o/p.

o/p:

[root@rss]# gcc d.c
d.c:6: error: expected ‘)’ before ‘*’ token
d.c:9: error: expected ‘)’ before ‘*’ token
d.c: In function ‘main’:
d.c:13: error: expected ‘;’ before ‘a’
d.c:14: error: ‘a’ undeclared (first use in this function)
d.c:14: error: (Each undeclared identifier is reported only once
d.c:14: error: for each function it appears in.)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. You omitted the typedef that you need to declare your struct alias s.
  2. The struct's member is b rather than a.
  3. You failed to return anything from your functions. These should be void functions.
  4. You need parens around ss in func1.
  5. The parameterless main in C is int main(void).

 

#include <stdio.h>

typedef struct s_{
        int b;
}s;

void func1(s** ss){
        (*ss)->b = 10;
}

void func(s* t){
        func1(&t);
}

int main(void)
{
        s a;
        func(&a);
        printf("
 a.b : %d 
", a.b);
        return 0;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...