Problema con dev c++
Posted by hyperion on 28-01-2009 14:48
ciao a tutti...utilizzando dev-c++ non riesco a compilare correttamente i seguenti sorgenti,mi dice che ho più di un main definito ma non capisco perchè ne ho solo uno!
Riporto l'errore che dev c++ mi da quando provo a compilare test.c con le seguenti opzioni : test.c stack.c
multiple definition of main
first defined here
..
..
suggerimenti?grazie mille..


Header file (stack.h)

PHP:

#ifndef STACK_H
#define STACK_H

void push( int n);
int pop();
int top(void);
int is_empty(void);
void make_empty(void);
void stampa(void);

#endif





Sorgente per l'header (stack.c)

PHP:

#include<stdio.h>
#include<stdlib.h>

#include "stack.h"

struct nodo{
int dato;
int h;
struct nodo *next;
};

int cont,h;
typedef struct nodo nodo;
nodo *testa = NULL;
nodo *tmp = NULL;


void push( int n){
    struct nodo *nuovo;
    nuovo = malloc(sizeof(struct nodo));
    if(nuovo == NULL) exit(0);
    nuovo -> dato = n;
    nuovo -> next = testa;    
    testa = nuovo;
}

int pop(void){
    tmp = testa;
    h = tmp->dato;
    testa = testa->next;
    return h;
}

int top(void){
    return testa->dato;
}

int is_empty(void){
    if(testa == NULL) return 1;
    else return 0;
}

void make_empty(void){
    while(is_empty()== 1)
        pop();
}

void stampa(void){
    tmp=testa;
    while(tmp !=NULL){
        printf("| %d |\n",tmp->dato);
        printf("|---|\n");
        tmp=tmp->next;
        }
}




Client di test (test.c)
PHP:

#include<stdio.h>
#include<stdlib.h>

#include "stack.h"

int main (){
    char c;
    int n,tmp;
    while( ( c = getchar ()) != 'f' ){

        switch(c){
            case '1': 
                scanf("%d",&n);
                push(n);
                printf("inserito: %d",n);
                break;
            case '2':
                tmp = pop();
                printf("tolto: %d",tmp);
                break;
            case '3':
                tmp = top();
                printf("in testa: %d",tmp);
                break;
            case '4': 
                tmp = is_empty();
                if(tmp==0)
                    printf("pila vuota");
                else printf("pila non vuota");
                break;
            case '5': 
                make_empty();    
                printf("pila svuotata");
                break;
            case '6': stampa();
                break;

        } // end switch
    }


return 0;
}


Powered by: vbHome (lite) v3.8 and vBulletin v2.3.1
Copyright © 2000 - 2002 Jelsoft Enterprises Limited