-4
#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("\n a : %d \n",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.)
Andreas Fester
  • 35,119
  • 7
  • 92
  • 115
Angus
  • 11,347
  • 28
  • 84
  • 146
  • 3
    Are you forgot the `typedef` keyword before `struct`? – Jayesh Bhoi Sep 19 '14 at 11:39
  • 6
    For one error, read about [operator precedence](http://en.cppreference.com/w/c/language/operator_precedence). For another error, there's no member in the structure named `a`. For yet *another* error, `s` is a variable. – Some programmer dude Sep 19 '14 at 11:40

3 Answers3

6
  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("\n a.b : %d \n", a.b);
        return 0;
}
David Heffernan
  • 587,191
  • 41
  • 1,025
  • 1,442
3

After looking your code, it's clear that you missed typedef keyword before struct

struct s_{
        int b;
}s;

should be

typedef struct s_{
        int b;
}s;

and for

*ss->a = 10; //wrong.  operator precedence problem
             // `->` operator have higher precedence than `*`

There is no member name a. It should be

(*ss)->b = 10;
Jayesh Bhoi
  • 22,676
  • 14
  • 57
  • 72
1

As shown s is an object of type struct s_. You can't use it as a type in the function prototypes. Did you mean to introduce a type alias with typedef?

BenMorel
  • 31,815
  • 47
  • 169
  • 296
Jens
  • 65,924
  • 14
  • 115
  • 171