doubt with structures and pointers..

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<stdio.h>
# include<stdlib.h>

struct manager {
char name[10];
int age;
int salary;
}biocon,panacea,serum;
manager *p;
int opt;
int main() {
	printf("DATABASE FOR BIOCON manager\n");
	printf("Please enter name: \n");
	scanf("%c",biocon.name);
	printf("Please enter age: \n");
	scanf("%d",&biocon.age);
	printf("Please enter salary: \n");
	scanf("%d",&biocon.salary);

	printf("DATABASE FOR PANACEA manager\n");
	printf("Please enter name: \n");
	scanf("%c",panacea.name);
	printf("Please enter age: \n");
	scanf("%d",&panacea.age);
	printf("Please enter salary: \n");
	scanf("%d",&panacea.salary);

	printf("DATABASE FOR SERUMBIOTEK manger\n");
	printf("Please enter name: \n");
	scanf("%c",serum.name);
	printf("Please enter age: \n");
	scanf("%d",&serum.age);
	printf("Please enter salary: \n");
	scanf("%d",&serum.salary);
	printf("please follow option 1:biocon,2:panacea,3:serum");
	scanf("%d",&opt);
	switch(opt) {
		case 1:
		manager *p=&biocon;
		break;
		case 2:
		manager *p=&panacea;
		break;
		case 3:
		manager *p=&serum;
		break;
		default:
		printf("please see menu\n");
		exit(1);
	}
	printf("the pay of %c is %d Rs whose age is %d years",p->name,p->salary,p->age);
 return 0;
}

in above code i m trying to use concepts of structure, pointers to a structure etc.while compiling i get following errors..
g++ -o pntrfunc /exploitation_studies/c++/pntrfunc.cpp
/exploitation_studies/c++/pntrfunc.cpp: In function ‘int main()’:
/exploitation_studies/c++/pntrfunc.cpp:41: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:42: error: redeclaration of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:39: error: ‘manager* p’ previously declared here
/exploitation_studies/c++/pntrfunc.cpp:44: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:45: error: redeclaration of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:39: error: ‘manager* p’ previously declared here
/exploitation_studies/c++/pntrfunc.cpp:47: error: jump to case label
/exploitation_studies/c++/pntrfunc.cpp:39: error: crosses initialization of ‘manager* p’
/exploitation_studies/c++/pntrfunc.cpp:51: warning: format ‘%c’ expects type ‘int’, but argument 2 has type ‘char*’

can some1 please explain where and why i am wrong and how to fix??
You are redeclaring manager *p multiple times within the switch. You should just be assigning it instead. IE, just get rid of the 'manager *' portion of the lines inside your switch.
 
  p = &biocon;
Topic archived. No new replies allowed.