Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Structure usage issue

Reply
Thread Tools

Structure usage issue

 
 
Pedro Pinto
Guest
Posts: n/a
 
      12-05-2006
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;
};

 
Reply With Quote
 
 
 
 
santosh
Guest
Posts: n/a
 
      12-05-2006
Pedro Pinto wrote:
> 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.

 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      12-05-2006
Pedro Pinto wrote:
>
> 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)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between Memory Usage and Heap Usage in my JVMMetrics ? Krist Java 8 02-10-2010 12:44 AM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:09 PM
retrieving CPU Usage and Memory Usage information in JAVA hvt Java 0 03-13-2007 01:07 PM
Webchecker Usage - a problem with local usage Colin J. Williams Python 1 02-26-2004 12:28 AM
Need help on memory usage VS PF usage metfan Java 2 10-21-2003 01:58 PM



Advertisments
 



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 54 55 56 57