Define a type

Hi,

I want to create a struct and use it in my program.In this case I want create this struct as a type. In my code I did create a "config.h" file. And my struct is in this file.

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
#ifndef LAST_TICKET
typedef struct {
        char routeName[10];
        char sePointOne[32];
	char sePointTwo[32];	
	char strtPoint[32];
	char endPoint[32];
	int fullTotal;
	int halfTotal;
	int lugeTotal;
	int payMethod;
	int cardNumber;
	int currentTripUpDownStatus;
	int currSecIndex;
	int destSecIndex;
	int ticketNumber;
	int tripNumber;
	double pasengerAmount;
	double fullAmount;
	double halfAmount;
	double lugeAmount;	
	double total;
	double balance;	
}LAST_TICKET;
#endif 



All configurations are inside of this file. The problem is If I call this file as "#include "config.h"" after that I can't call again this file any ware in my application. A am new to c and I want to do create a struct as a type and use it any ware in an application.

Thank you.
@dushantha12
The problem is If I call this file as "#include "config.h"" after that I can't call again this file any ware in my application.


You should still be able to use the struct like this in a .cpp file for example:

LAST_TICKET.balance = 1000.0;

Does this work for you?
Hi,


TheIdeasMan, thanks for reply. Actually it's working. I mean This. Suppose, I have config.h,a.c and b.c files. Now I have two typdef struct's in config.h for a.c file and b.c file. There are no relation between a.c and b.c. If I do include config.h in a.c it's working for a.c but not foe b.c. If I do include config.h in b.c it's working for b.c but not foe a.c. So now what I want to do.

Thanks.
The problem is If I call this file as "#include "config.h"" after that I can't call again this file any ware in my application.

Wrong.
In your case this is true because you didn't write the header guards correctly.
1
2
3
4
5
6
#ifndef LAST_TICKET
#define LAST_TICKET

// typedef struct ...

#endif 


Many people like giving header guards the name of the file:
1
2
3
4
#ifndef CONFIG_H
#define CONFIG_H

#endif 


Last but not least, many compilers support #pragma once which replaces the header guards completely.
1
2
3
#pragma once

// typedef struct ... 

http://en.wikipedia.org/wiki/Pragma_once
Hi,

wow amazing.... Thank you very much Its work.Thank you to all.
Topic archived. No new replies allowed.