Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I try to make a print function for structure but meet a errow I have not seem before
this is my cod:


C++
   #include<stdio.h>
   struct point{
	int x;
	int y;
   }p;
   
    int main()
   {
        struct point scan(struct point *p);
	void print(struct point *p);
	
		
	scan(&p);
	print(&p);
	
	 
	
	return 0;
}
     struct point scan(struct point *p)
{
	scanf("%d%d",p->x,p->y); 
}

      void print(struct point *p)
{
	printf("%d%d",p->x,p->y);
}


What I have tried:

I have searched google but nothing found nothing.
By the way,if you think my question is stupid,please recommend some book for me, I will appreciate that.
Posted
Updated 5-Nov-16 21:44pm
Comments
Michael_Davies 6-Nov-16 1:55am    
Which line gives the error and what does the error message say?

Definitions should be outside functions so

struct point scan(struct point *p);
void print(struct point *p);

Should not be inside Main.

1 solution

You cannot declare function prototypes inside the body of a function. Move these lines above the definition of main:
C++
struct point scan(struct point *p);
	void print(struct point *p);


And do yourself a favour, and don't use single character names: use "proper" names and your code becomes a lot easier to read.
C++
#include<stdio.h>
struct point
   {
   int x;
   int y;
   } myPoint;

struct point scan(struct point *p);
void print(struct point *p);
   
int main()
   {
   scan(&myPoint);
   print(&myPoint);
   return 0;
   }
   
struct point scan(struct point *p)
   {
   scanf("%d%d",p->x,p->y); 
   }
void print(struct point *p)
   {
   printf("%d%d",p->x,p->y);
   }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900