0

What is a new project programming ? Is it better writting code in separate files which they can combine together ... rather that making ine file that includes all the other .C files ?

At last... if i have 3 files .. for example:
File one:

// * Filename: setadt.c

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


void Dimiourgia(typos_synolou synolo) 
/* Ëåéôïõñãßá: Äçìéïõñãåß Ýíá óýíïëï ÷ùñßò óôïé÷åßá, äçëáäÞ ôï êåíü óýíïëï. 
   ÅðéóôñÝöåé: Ôï êåíü óýíïëï 
*/
{
    stoixeio_synolou i;

    for (i = 1; i <= megisto_plithos; i++)
        synolo[i] = FALSE;
}

void Katholiko(typos_synolou synolo) 
/* ÄÝ÷åôáé:     ¸íá óýíïëï. 
   Ëåéôïõñãßá: Äçìéïõñãåß Ýíá óýíïëï ìå üëá ôá óôïé÷åßá ðáñüíôá, 
                Ýôóé üðùò ïñßóôçêå óôï ôìÞìá äçëþóåùí ôïõ ðñïãñÜììáôïò. 
   ÅðéóôñÝöåé: Ôï êáèïëéêü óýíïëï ðïõ äçìéïõñãÞèçêå 
*/
{
    stoixeio_synolou i;

    for (i = 1; i <= megisto_plithos; i++)
        synolo[i] = TRUE;
}

void Eisagogi(stoixeio_synolou stoixeio, typos_synolou synolo) 
/* ÄÝ÷åôáé:    ¸íá óýíïëï êáé Ýíá óôïé÷åßï. 
   Ëåéôïõñãßá: ÅéóÜãåé ôï óôïé÷åßï óôï óýíïëï. 
   ÅðéóôñÝöåé: Ôï ôñïðïðïéçìÝíï óýíïëï 
*/
{
    synolo[stoixeio] = TRUE;
}

void Diagrafi(stoixeio_synolou stoixeio, typos_synolou synolo) 
/* ÄÝ÷åôáé:     ¸íá óýíïëï êáé Ýíá óôïé÷åßï. 
   Ëåéôïõñãßá:  ÄéáãñÜöåé ôï óôïé÷åßï áðü ôï óýíïëï. 
   ÅðéóôñÝöåé:  Ôï ôñïðïðïéçìÝíï óýíïëï 
*/
{
    synolo[stoixeio] = FALSE;
}

boolean Melos(stoixeio_synolou stoixeio, typos_synolou synolo) 
/* ÄÝ÷åôáé:    ¸íá óýíïëï êáé Ýíá óôïé÷åßï. 
   Ëåéôïõñãßá: ÅëÝã÷åé áí ôï óôïé÷åßï åßíáé ìÝëïò ôïõ óõíüëïõ. 
   ÅðéóôñÝöåé: ÅðéóôñÝöåé TRUE áí ôï óôïé÷åßï åßíáé ìÝëïò ôïõ êáé FALSE äéáöïñåôéêÜ 
*/
{
    return synolo[stoixeio];
}

boolean KenoSynolo(typos_synolou synolo) 
/*
ÄÝ÷åôáé: ¸íá óýíïëï. 
 Ëåéôïõñãßá: ÅëÝã÷åé áí ôï óýíïëï åßíáé êåíü. 
 ÅðéóôñÝöåé: ÅðéóôñÝöåé TRUE áí ôï óýíïëï åßíáé êåíü êáé FALSE äéáöïñåôéêÜ 
*/
{
    stoixeio_synolou i;
    boolean keno; 

    keno=TRUE;
    i = 1;

    while (i <= megisto_plithos  && keno) {
        if (Melos(i, synolo))
            keno = FALSE;
        else
            i++;
    }
    return keno;
}

boolean IsaSynola(typos_synolou s1, typos_synolou s2) 
/* ÄÝ÷åôáé:     Äýï óýíïëá s1 êáé s2. 
   Ëåéôïõñãßá: ÅëÝã÷åé áí ôá äýï óýíïëá åßíáé ßóá. 
   ÅðéóôñÝöåé: ÅðéóôñÝöåé TRUE áí ôá äýï óýíïëá Ý÷ïõí ôá ßäéá óôïé÷åßá êáé FALSE äéáöïñåôéêÜ 
*/
{
    stoixeio_synolou i;
    boolean isa;

    isa = TRUE;
    i=1;
    while ((i <= megisto_plithos) && isa)
        if (Melos(i,s1) != Melos(i,s2))
            isa = FALSE;
        else
            i++;
    return isa;
}

boolean Yposynolo(typos_synolou s1, typos_synolou s2) 
/* ÄÝ÷åôáé:     Äýï óýíïëá s1 êáé s2. 
   Ëåéôïõñãßá: ÅëÝã÷åé áí ôï óýíïëï s1 åßíáé õðïóýíïëï ôïõ s2. 
   ÅðéóôñÝöåé: ÅðéóôñÝöåé true áí ôï óýíïëï s1 åßíáé Ýíá õðïóýíïëï ôïõ s2, 
                äçëáäÞ áí êÜèå óôïé÷åßï ôïõ s1 åßíáé êáé óôïé÷åßï ôïõ s2 
*/
{
    stoixeio_synolou i;
    boolean yposyn;

    yposyn = TRUE;
    i=1;
    while (i <= megisto_plithos && yposyn)
        if (Melos(i, s1) && !Melos(i, s2))
            yposyn = FALSE;
        else
            i++;
    return yposyn;
}

void EnosiSynolou(typos_synolou s1, typos_synolou s2, typos_synolou enosi) 
/* ÄÝ÷åôáé:     Äýï óýíïëá s1 êáé s2. 
   Ëåéôïõñãßá: Äçìéïõñãåß Ýíá íÝï óýíïëï ìå ôá óôïé÷åßá ðïõ áíÞêïõí Þ óôï s1 Þ 
                óôï s2 Þ êáé óôá äýï óýíïëá.  
   ÅðéóôñÝöåé: ÅðéóôñÝöåé ôï óýíïëï enosi ðïõ ðñïêýðôåé áðü ôçí Ýíùóç ôùí óõíüëùí s1 êáé s2 
*/
{
    stoixeio_synolou i;

    for (i = 1; i <= megisto_plithos; i++)
        enosi[i] = Melos(i, s1) || Melos(i, s2);
}

void TomiSynolou(typos_synolou s1, typos_synolou s2, typos_synolou tomi) 
/* ÄÝ÷åôáé:     Äýï óýíïëá s1 êáé s2. 
   Ëåéôïõñãßá: Äçìéïõñãåß Ýíá íÝï óýíïëï ìå ôá óôïé÷åßá ðïõ áíÞêïõí êáé óôá äýï óýíïëá s1 êáé s2.  
   ÅðéóôñÝöåé: ÅðéóôñÝöåé ôï óýíïëï tomi ðïõ ðñïêýðôåé áðü ôçí ôïìÞ ôùí óõíüëùí s1 êáé s2 
*/
{
    stoixeio_synolou i;

    for (i = 1; i <= megisto_plithos; i++)
        tomi[i] = Melos(i, s1) && Melos(i, s2);
}

void DiaforaSynolou(typos_synolou s1, typos_synolou s2, typos_synolou diafora) 
/* ÄÝ÷åôáé: Äýï óýíïëá s1 êáé s2. 
 Ëåéôïõñãßá: Äçìéïõñãåß Ýíá íÝï óýíïëï ìå ôá óôïé÷åßá ðïõ áíÞêïõí óôï óýíïëï s1 êáé äåí áíÞêïõí óôï s2.  
 ÅðéóôñÝöåé: ÅðéóôñÝöåé ôï óýíïëï diafora ðïõ ðñïêýðôåé áðü ôçí äéáöïñÜ ôùí óõíüëùí s1-s2. 
*/
{
    stoixeio_synolou i;

    for (i = 1; i <= megisto_plithos; i++)
        diafora[i] = Melos(i, s1) && (!Melos(i, s2));
}

Second file:

// * Filename: setADT.h

#define megisto_plithos 10          //ìÝãéóôï ðëÞèïò óôïé÷åßùí óõíüëïõ

typedef enum {
    FALSE, TRUE
} boolean;

typedef boolean typos_synolou[megisto_plithos+1];
typedef int stoixeio_synolou;

void Dimiourgia(typos_synolou synolo);
void Katholiko(typos_synolou synolo);
void Eisagogi(stoixeio_synolou stoixeio, typos_synolou synolo);
void Diagrafi(stoixeio_synolou stoixeio, typos_synolou synolo);
boolean Melos(stoixeio_synolou stoixeio, typos_synolou synolo);
boolean KenoSynolo(typos_synolou synolo);
boolean IsaSynola(typos_synolou s1, typos_synolou s2);
boolean Yposynolo(typos_synolou s1, typos_synolou s2);
void EnosiSynolou(typos_synolou s1, typos_synolou s2, typos_synolou enosi);
void TomiSynolou(typos_synolou s1, typos_synolou s2, typos_synolou tomi);
void DiaforaSynolou(typos_synolou s1, typos_synolou s2, typos_synolou diafora);

Third file:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "SetADT.h"

void menu(int *choice);
void displayset(typos_synolou set);

main()
{
    stoixeio_synolou AnItem;
    int choice, s;
    typos_synolou set, set1, set2, tomi, enosi,diafora;
    char ch;

    do
   {
        menu(&choice);
        switch(choice)
        {
             case 1: Dimiourgia(set1);
                     printf("\nset1\n"); 
                     displayset(set1);
                     Dimiourgia(set2);
                     printf("\nset2\n"); 
                     displayset(set2);
                     break;
             case 2: Katholiko(set);
                     break;
             case 3: printf("\nDWSE set 1 or 2 ");
                     scanf("%d",&s);
                     do
                     {
                        printf("DWSE ARI8MO GIA EISAGWGH STO set: ");
                        scanf("%d", &AnItem);  
                        if (s==1)
                            Eisagogi(AnItem,set1); 
                        else 
                            Eisagogi(AnItem,set2);                     
                        printf("\nContinue Y/N: ");
                        do
                        {
                             scanf("%c", &ch);
                        } while (toupper(ch)!= 'N' && toupper(ch)!= 'Y');
                    } while (toupper(ch)!='N');
                    if (s==1)
                        displayset(set1);
                    else displayset(set2);
                    break;
             case 4: printf("\nDWSE STOIXEIO ");
                     scanf("%d",&AnItem);
                     printf("\nDWSE set 1 or 2 ");
                     scanf("%d",&s);
                     if (s==1) {
                        Diagrafi(AnItem, set1);
                        displayset(set1);
                     }
                     else {
                        Diagrafi(AnItem, set2);
                        displayset(set2);
                     }
                     break;
             case 5: printf("\nDWSE STOIXEIO ");
                     scanf("%d",&AnItem);
                     printf("\nDWSE set 1 or 2 ");
                     scanf("%d",&s);
                     if (s==1) 
                        if (Melos(AnItem, set1))
                            printf("%d einai melos tou set1\n",AnItem);
                        else printf("%d den einai melos tou set1\n",AnItem);
                     else 
                        if (Melos(AnItem, set2))
                            printf("%d einai melos tou set2\n",AnItem);
                        else printf("%d den einai melos tou set2\n",AnItem);
                     break;
             case 6: printf("\nDWSE set 1 or 2 ");
                     scanf("%d",&s);
                     if (s==1)
                        if (KenoSynolo(set1))
                             printf("Empty set1\n");
                        else printf("not Empty set1\n");
                     else 
                        if (KenoSynolo(set2)) 
                            printf("Empty set2\n");
                        else printf("not Empty set2\n");
                     break;
             case 7: if (IsaSynola(set1,set2))
                         printf("isa\n");
                     else printf("Not isa sets\n");
                     break;
             case 8: printf("\nDWSE set 1 or 2 ");
                     scanf("%d",&s);
                     if (s==1) 
                        if (Yposynolo(set1,set2))
                         printf("set1 yposynolo tou set2\n");
                         else printf("Not yposynolo\n");
                     else if (Yposynolo(set2,set1))
                         printf("set2 yposynolo tou set1\n");
                         else printf("Not yposynolo\n");
                     break; 
             case 9: EnosiSynolou(set1,set2,enosi);
                     printf("ENWSH\n");
                     displayset(enosi);
                     break;
             case 10: TomiSynolou(set1,set2,tomi);
                      displayset(tomi);
                     break;
             case 11: DiaforaSynolou(set1,set2,diafora);
                      printf("DIAFORA\n");
                      displayset(diafora);
                      break;       
        }
        } while (choice!=12);
        return 0;
        system("PAUSE");
}

void menu(int *choice)
{
  printf("\nXRHSIMOPOIHSE TIS PARAKATW ENTOLES GIA NA ELEGJEIS TO unit SetADT\n");
  printf("1 ---- DHMIOYRGIA SYNOLOU\n");
  printf("2 ---- KA8OLIKO\n");
  printf("3 ---- EISAGWGH\n");
  printf("4 ---  DIAGRAFH\n");
  printf("5 ---  MELOS\n");
  printf("6 ---- KENO SYNOLO\n");
  printf("7 ---- ISA SYNOLA\n");
  printf("8 ---- YPOSYNOLO\n");
  printf("9 ---- ENOSH 2 SYNOLWN\n");
  printf("10 ---- TOMH 2 SYNOLWN\n");
  printf("11 ---- DIAFORA SYNOLOU\n");
  printf("12 ---- EXIT\n");
  printf("\nChoice 1-12: ");
  do
    {
        scanf("%d", choice);
    } while (*choice<1 && *choice>12);
}


void displayset(typos_synolou set)
{
    stoixeio_synolou i;

    for (i=1;i <= megisto_plithos;i++)
    {
        if((set[i]))
            printf(" %d",i);
    }
    printf("\n");
}

How i can combine them together ? (merge)

2
Contributors
1
Reply
14
Views
4 Years
Discussion Span
Last Post by deceptikon
1

How i can combine them together ?

That depends on your compiler, really. If you're using an IDE you can just lump everything together in the same project and then build it. The IDE will take care of the grunt work. If you're using a command line compiler, they tend to be fairly consistent in that you provide all of the .c files for compilation (the .h files will be handled automatically) and they will be compiled then linked into an executable:

$ gcc SetADT.c main.c

You can also compile them separately and link them:

$ gcc -c SetADT.c
$ gcc -c main.c
$ gcc SetADT.o main.o

The options and extensions may be different, but that's the general pattern for command line compilation.

Edited by deceptikon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.