Bonjour,
J'ai fait des modifications dans mon code que je soumets ci-dessous et cela fonctionne en langage C sous Windows avec CodeBlock. Maintenant, je dois le transcrire pour un PC tournant sous MAC.
Je suis débutante en langage C et j'ai beaucoup appris grâce à toi et tes conseils
Merci de ton aide précieuse.
A bientôt
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <string.h>
#define TAILLE_MAX 1000
char *str_sub (const char *s, unsigned int start, unsigned int end) {
char *new_s = NULL;
if (s != NULL && start < end) {
new_s =(char*) malloc (sizeof (*new_s) * (end - start + 2));
if (new_s != NULL)
{
int i;
for (i = start; i <= end; i++)
{
new_s[i-start] = s[i];
}
new_s[i-start] = '\0';
}
else
{
fprintf (stderr, "Memoire insuffisante\n");
exit (EXIT_FAILURE);
}
}
return new_s;
}
int longueurChaine(const char* chaine)
{
int nombreDeCaracteres = 0;
char caractereActuel = 0;
do
{
caractereActuel = chaine[nombreDeCaracteres];
nombreDeCaracteres++;
}
while(caractereActuel != '\0'); // On boucle tant qu'on n'est pas arrivé à l'\0
nombreDeCaracteres--; // On retire 1 caractère de long pour ne pas compter le caractère \0
return nombreDeCaracteres;
}
int main(int argc, char *argv[])
{
FILE* fichier = NULL;
int compteur;
int v;
char Expl11[TAILLE_MAX] = "action=";
char Expl12[TAILLE_MAX] = "ADDPAT";
char Expl2[TAILLE_MAX] = "&";
char Expl3[TAILLE_MAX] = "user=125784b92703c";
char Expl4[TAILLE_MAX] = "code_labo=0";
char Expl5[TAILLE_MAX] = "id_med=9997";
char Expl6[TAILLE_MAX] = "num=";
char Expl61[TAILLE_MAX] = "987654";
char Expl7[TAILLE_MAX] = "nom=NAIMARRE";
char Expl8[TAILLE_MAX] = "prenom=Jean";
char Expl9[TAILLE_MAX] = "sexe=H";
char Exp20[TAILLE_MAX] = "naissance=19101010";
char Exp21[TAILLE_MAX] = "adresse=Route de Satigny,42";
char Exp22[TAILLE_MAX] = "cp=1217";
char Exp23[TAILLE_MAX] = "ville=Meyrin";
char Exp24[TAILLE_MAX] = "pays=Suisse";
char Exp25[TAILLE_MAX] = "tel=";
char Exp26[TAILLE_MAX] = "mobile=";
char Exp27[TAILLE_MAX] = "email=";
char Exp28[TAILLE_MAX] = "open=1";
char Exp29[TAILLE_MAX] = "\"";
int longueur = 0;
int longcalcul = 0;
char Expl[TAILLE_MAX] = "start http://www.google.ch";
char Explor[TAILLE_MAX] =
"start explorer \"https://www.proxilis.ch/directlab/link_doc.php?";
char Explore[TAILLE_MAX] = "";
char Explorer[TAILLE_MAX] = "";
char ExplorerAdd[TAILLE_MAX] = "&";
char Explorer1[TAILLE_MAX] = "start explorer \"https://www.proxilis.ch/directlab/link_doc.php?";
char ExplorerNum[TAILLE_MAX] = "num=";
char ExplorerNom[TAILLE_MAX] = "nom=";
char ExplorerPreNom[TAILLE_MAX] = "prenom=";
char ExplorerSexe[TAILLE_MAX] = "sexe=";
char ExplorerNaissance[TAILLE_MAX] = "naissance=";
char ExplorerAdresse[TAILLE_MAX] = "adresse=";
char ExplorerCP[TAILLE_MAX] = "cp=";
char ExplorerVille[TAILLE_MAX] = "ville=";
char ExplorerPays[TAILLE_MAX] = "pays=";
char ExplorerTel[TAILLE_MAX] = "tel=";
char ExplorerMobile[TAILLE_MAX] = "mobile=";
char ExplorerEmail[TAILLE_MAX] = "email=";
char *action = "";
char *id_med = "";
char *user = "";
char *code_labo = "";
char open[TAILLE_MAX] = "";
char chaine[TAILLE_MAX] = "";
char chaineTemporaire[TAILLE_MAX] = "";
char *num = "";
char *nom = "";
char *prenom = "";
char sexe[TAILLE_MAX] = "";
char sexenum[TAILLE_MAX] = "";
char naissance[TAILLE_MAX] = "";
char jjnaissance[2] = "";
char mmnaissance[2] = "";
char aanaissance[2] = "";
char *adresse = "";
char cp[TAILLE_MAX] = "";
char *ville = "";
char pays[TAILLE_MAX] = "";
char tel[TAILLE_MAX] = "";
char mobile[TAILLE_MAX] = "";
char email[TAILLE_MAX] = "";
char Reseau[TAILLE_MAX] = "";
char *ptr = "";
char *ptr3000;
char *ptr3101;
char *ptr3102;
char *ptr3103;
char *ptr3106;
char *ptr3107;
char *ptr3110;
char *ptr3626;
char *str1 = "";
char *str2 = "3000";
char *str3000 = "3000";
char *str3101 = "3101";
char *str3102 = "3102";
char *str3103 = "3103";
char *str3106 = "3106";
char *str3107 = "3107";
char *str3110 = "3110";
char *str3626 = "3626";
char *resultat3000 = "";
char *sexefille = "2";
char *sexegarcon = "1";
char *new_s = NULL;
char *new_ville = NULL;
char *new_cp = NULL;
char *new_jj = NULL;
char *new_mm = NULL;
char *new_aa = NULL;
unsigned int start;
unsigned int end;
/* Ouverture du fichier CBLEtilab.ini */
fichier = fopen("c:\\etilab\\import\\CBLEtilab.ini", "r");
compteur = -1;
new_s = NULL;
if (fichier != NULL)
{
while (fgets(chaine, TAILLE_MAX, fichier) != NULL) // On lit le fichier tant qu'on ne reçoit pas d'erreur (NULL)
{
++compteur;
if (compteur == 0)
{
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
action = str_sub (chaineTemporaire, 0, longcalcul);
}
if (compteur == 1)
{
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
id_med = str_sub (chaineTemporaire, 0, longcalcul);
}
if (compteur == 2)
{
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
user = str_sub (chaineTemporaire, 0, longcalcul);
}
if (compteur == 3)
{
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
code_labo = str_sub (chaineTemporaire, 0, longcalcul);
}
if (compteur == 4)
{
strcpy(open, chaine);
}
}
/* Fermeture du fichier */
fclose(fichier);
}
/* Ouverture du fichier GDTEtilab.GDT */
fichier = fopen("c:\\etilab\\import\\GDTEtilab.GDT", "r");
compteur = -1;
if (fichier != NULL)
{
while (fgets(chaine, TAILLE_MAX, fichier) != NULL) // On lit le fichier tant qu'on ne reçoit pas d'erreur (NULL)
{
++compteur;
str1 = str_sub (chaine, 1, 1000);
/* CHAINE */
new_s = NULL;
start = 7;
end = 100;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_s = str_sub (chaineTemporaire, start, end);
/* VILLE */
new_ville = NULL;
start = 12;
end = 100;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_ville = str_sub (chaineTemporaire, start, end);
/* CP */
new_cp = NULL;
start = 7;
end = 10;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_cp = str_sub (chaineTemporaire, start, end);
/* JJNAISSANCE */
new_jj = NULL;
start = 7;
end = 8;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_jj = str_sub (chaineTemporaire, start, end);
/* MMNAISSANCE */
new_mm = NULL;
start = 9;
end = 10;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_mm = str_sub (chaineTemporaire, start, end);
/* AANAISSANCE */
new_aa = NULL;
start = 11;
end = 14;
strcpy(chaineTemporaire, chaine);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 3;
new_aa = str_sub (chaineTemporaire, start, end);
/* 3000 */
ptr3000 = "";
ptr3000 = strstr(str1, str3000);
if (ptr3000 != NULL)
{
strcpy(chaineTemporaire, new_s);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
num = str_sub (chaineTemporaire, 0, longcalcul);
}
/* 3101 */
ptr3101 = "";
ptr3101 = strstr(str1, str3101);
if (ptr3101 != NULL)
{
//* strcpy(nom, new_s);
strcpy(chaineTemporaire, new_s);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
nom = str_sub (chaineTemporaire, 0, longcalcul);
}
/* 3102 */
ptr3102 = "";
ptr3102 = strstr(str1, str3102);
if (ptr3102 != NULL)
{
strcpy(chaineTemporaire, new_s);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
prenom = str_sub (chaineTemporaire, 0, longcalcul);
}
/* 3103 */
ptr3103 = "";
ptr3103 = strstr(str1, str3103);
if (ptr3103 != NULL)
{
strcat(naissance, new_aa);
strcat(naissance, new_mm);
strcat(naissance, new_jj);
}
/* 3106 */
ptr3106 = "";
ptr3106 = strstr(str1, str3106);
if (ptr3106 != NULL)
{
strcpy(cp, new_cp);
strcpy(chaineTemporaire, new_ville);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
ville = str_sub (chaineTemporaire, 0, longcalcul);
}
/* 3107 */
ptr3107 = "";
ptr3107 = strstr(str1, str3107);
if (ptr3107 != NULL)
{
strcpy(chaineTemporaire, new_s);
longueur = longueurChaine(chaineTemporaire);
longcalcul = longueur - 2;
adresse = str_sub (chaineTemporaire, 0, longcalcul);
}
/* 3110 */
ptr3110 = "";
ptr3110 = strstr(str1, str3110);
if (ptr3110 != NULL)
{
strcpy(sexenum, new_s);
v = strncmp(sexenum, sexefille, 1);
if (v == 0)
{
strcpy(sexe, "F");
}
v = strncmp(sexenum, sexegarcon, 1);
if (v == 0)
{
strcpy(sexe, "H");
}
ptr3626 = "";
ptr3626 = strstr(str1, str3626);
if (ptr3626 != NULL)
{
strcpy(tel, new_s);
}
}
}
/* Fermeture du fichier */
fclose(fichier);
}
/* URL */
strcat(Explorer, Explorer1);
strcat(Explorer, action);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, user);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, code_labo);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, id_med);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerNum);
strcat(Explorer, num);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerNom);
strcat(Explorer, nom);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerPreNom);
strcat(Explorer, prenom);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerSexe);
strcat(Explorer, sexe);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerNaissance);
strcat(Explorer, naissance);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerAdresse);
strcat(Explorer, adresse);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerCP);
strcat(Explorer, cp);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerVille);
strcat(Explorer, ville);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerPays);
strcat(Explorer, pays);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerTel);
strcat(Explorer, tel);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerMobile);
strcat(Explorer, mobile);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, ExplorerEmail);
strcat(Explorer, email);
strcat(Explorer, ExplorerAdd);
strcat(Explorer, open);
//* printf("Explorer : %s\n", Explorer);
system(Explorer);
return 0;
}