-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
  • 36,091
  • 7
  • 95
  • 123
Angus
  • 12,133
  • 29
  • 96
  • 151
  • 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
  • 601,492
  • 42
  • 1,072
  • 1,490
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
  • 24,694
  • 15
  • 58
  • 73
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
  • 34,448
  • 50
  • 182
  • 322
Jens
  • 69,818
  • 15
  • 125
  • 179