Structure usage issue

P

Pedro Pinto

Hi there!

I'm presented with the following situation:

I'm writing a server program that receives information and saves it to
a structure i've created that goes by the name of tabela.

The entire program has 6 files:

projecto.h
serv.h
servsql.h
linkedlist.c
serv_aux.c
servsql.c // this is were main() is

My issue is, i've declared the structure tabela in the file linkedlist.
I can use the functions defined in linkedlist in servsql (were main
is), but i cannot create a variable of the type tabela there... What is
wrong??? I've searched the web for some tutorial but failed to find any
result. Thanks in advance for any help. Bellow you can see the
beginning of every file.

Regards

Pedro Pinto


------------------------------
projecto.h
------------------------------
#ifndef PROJECTO_H
#define PROJECTO_H


#define BUFFSIZE 6804
#define LENGTH 4


#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>

#endif

------------------------------
servsql.h
------------------------------
#ifndef SERVSQL
#define SERVSQL

#include "linkedlist.c"
#include "serv_aux.c"
#include "servsql.c"

int main(int argc, char* argv[]);

void syntax();

void checkParameters(int argc);

void checkPort(int porto_servidor);



#endif

-----------------------------
serv.h
-----------------------------

#ifndef SERV_H
#define SERV_H


#include "projecto.h"

void syntax();

void checkParameters(int argc);

void checkPort(int porto_servidor);

void printMessage(char buff[]);

void trataMsgCreateInsert(char array[], char result[]);

void trataMsgUpdateSelect(char array[], char result[]);

int criaMensagem(int id, int cod, char pedido[], char *buffer);

void getPedido(char buf[], char result[]);

int getId(char buf[]);

int getCod(char buf[]);

int getSizeQuery(char buf[]);


------------------------------------
servsql.c
------------------------------------

#include "serv.h"


/* Função Main */
int main (int argc, char *argv[]) {

------------------------------------
serv_aux.c
------------------------------------

#include "serv.h"


------------------------------------
linkedlist.c
------------------------------------

#include "projecto.h"



typedef struct tabela tabela;
struct tabela {
char nome[50];
int nColunas;
int nLinhas;
char nomeColunas[10][50];
char valores[50][10][65];
tabela *next;
};
 
S

santosh

Pedro said:
Hi there!

I'm presented with the following situation:

I'm writing a server program that receives information and saves it to
a structure i've created that goes by the name of tabela.

The entire program has 6 files:

projecto.h
serv.h
servsql.h
linkedlist.c
serv_aux.c
servsql.c // this is were main() is

My issue is, i've declared the structure tabela in the file linkedlist.
I can use the functions defined in linkedlist in servsql (were main
is), but i cannot create a variable of the type tabela there... What is
wrong??? I've searched the web for some tutorial but failed to find any
result. Thanks in advance for any help. Bellow you can see the
beginning of every file.

Put common declarations like the tabela into one of the header files
and include it from servsql.c. If you want to use an opaque structure
then you must provide accessor functions.
 
C

CBFalconer

Pedro said:
I'm writing a server program that receives information and saves
it to a structure i've created that goes by the name of tabela.

The entire program has 6 files:

projecto.h
serv.h
servsql.h
linkedlist.c
serv_aux.c
servsql.c // this is were main() is

My issue is, i've declared the structure tabela in the file
linkedlist. I can use the functions defined in linkedlist in
servsql (were main is), but i cannot create a variable of the
type tabela there... What is wrong??? I've searched the web for
some tutorial but failed to find any result. Thanks in advance
for any help. Bellow you can see the beginning of every file.

Most of your post is off-topic, because it refers to things unknown
to standard C. To start with, all the following headers are
unknown:

#include <sys/socket.h>
#include <sys/types.h>
#include <sys/time.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>

but there is a larger C question here. If you defined your
"tabela" in linkedlist.c, and need that definition elsewhere, you
need to publish it in the interface definition for linkedlist.c.
The usual way to do this is to place the definition in
linkedlist.h, and #include "linkedlist.h" in every .c file that
needs to know about it.

The purpose of .h files is to expose the portions of the
corresponding .c file that you wish known elsewhere. You also
#include "linkedlist.h" in linkedlist.c to ensure that it also uses
the same definitions or prototypes. You then #include
"linkedlist.h" in each .c file that needs to access those
definitions or prototypes.

Think of the .h file as the link between independent .c files. Not
as a convenient place to stuff prototypes etc. You *never* declare
variables or function bodies in a .h file. Also get in the habit
of marking all functions and file scope variables (in the .c file)
which you do not wish to expose as static.

Before posting again here, read the links below:

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/> (C99)
<http://www.dinkumware.com/refxc.html> (C-library}
<http://gcc.gnu.org/onlinedocs/> (GNU docs)
<http://clc-wiki.net> (C-info)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top