Mon programme ne fonctionne pas aidez moi

djo -  
 djo -
Bonjour,
j'ai un petit souci sur mon prg C sous linux ,en fait j'ai prog c découpé en module module ou fichier helloworld .c un autre helloworld.h et le dernier main.c finalement le prog doit afficher "hello world" j'ai suivi les instruction d'un document mais il m'affiche toujours des erreurs voila les différents fichier :

/* helloworld.h */
const char *hw = "hello world!";
void print_hello_world();

/* helloworld.c */
#include "helloworld.h"
#include <stdio.h>
void print_hello_world() {
printf("%s\n", hw);
}

/* main.c */
#include "helloworld.h"
int main(int argc, char **argv) {
print_hello_world();
return

pour compiler j'ai fait:
$ gcc -Wall helloworld.c main.c -o hello
$ ./hello

même si j'exicute les fichiers chacun tout seul sa marche pas toujours il m'affiche
l'erreur afficher est :

mutiple definition of "hw"
first defined here
ld returned 1 exit status

voila donc mon prob s'il vous si vous avez une réponse dite moi comment faire avec détail et merci

2 réponses

lami20j Messages postés 21331 Date d'inscription   Statut Modérateur, Contributeur sécurité Dernière intervention   3 570
 
Salut,

Au lieu de
<ital>/* helloworld.h */
const char *hw = "hello world!";
void print_hello_world();
</ital>

écrit dans helloworld.h
#ifndef HELLOWORLD_H
#define HELLOWORLD_H


/* helloworld.h */
const char *hw = "hello world!";
void print_hello_world(); 

#endif

0
djo
 
en fait j'ai essayer déjà sa mais sa marche pas toujours c vraiment bizarre qu'est ce que je fait
0