How to fix the error?thx a lot

Line 10: expression cannot be used as a function

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

struct Point{
int x;
int y;
};
int Point_init(struct Point* b){
(*b).x=0
/*line10*/(*b).y=0;
}
int main(){
struct Point a;
struct Point* p;
p=&a;
Point_init(&a);
printf("Point(%d %d)",a.x,a.y);
}
There should be a semicolon at the end of line 9. (*b).x=0 ;

Point_init should return some value of type int.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>

// this typedef makes the code more readable
typedef struct Point Point ;

struct Point
{
    int x;
    int y;
};

// if there is nothing to return, make the return type void
void Point_init( Point* p )
{
    if( p != NULL ) // this sanity check may be a good idea
        p->x = p->y = 0 ; // equivalent to (*p).x = (*p).y = 0 ;
}

int main()
{
    Point a;
    Point* p = &a ;

    Point_init(p) ;
    printf( "Point(%d,%d)\n", a.x, a.y );
}
Last edited on
thx bro,i make a stupid mistake.And ur advice is very useful to me!
Topic archived. No new replies allowed.