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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include <stdio.h>
#include <stdlib.h>
#include"matrice.c"
# define MAX 0
//fonction puissance//////////////////////////
int puissance(int nb,int exposant)
{
int resu=nb;
int k=1;
if (exposant>0)
{
for (k=1;k<exposant;k++)
{
resu=resu*nb;
}
}
if (exposant==0)
{
resu=1;
}
return resu;
}
//fonction qui converti une matrice en chaine////////////////////////////////
char* mattoc(matrice *mat)
{
char* resultat;
char buf[1];
char final[1024];
resultat="\0";
int i,j;
final[1024]="\0";
for (i=0 ; i<(*mat).nbl ;i++)
{
for (j=0 ; j<(*mat).nbc ;j++)
{
//printf("%d\n",j);
sprintf(buf,"%d",(*mat).tab[i][j]);
strcat(final,buf);
if (j!=2){strcat(final,",");}
}
strcat(final,"/");
}
resultat=final;
return resultat;
}
//fonction qui converti une chaine en matrice////////////////////////////////
matrice *ctomat(char *final)
{
matrice *mat;
char buffer;
int nblu=0;
int compt=0;
int nbl=0;
int nbc=0;
int nb=0;
int n;
int k=0;
int i=0;
int j=0;
char temp[500]="\0";
printf("on rentre dans la fonction\n");
strcpy(temp,final);
printf(" le chaine a converir est %s\n",temp);
printf("on fait %d\n",strlen(temp));
while(compt<strlen(temp))
{
printf("on rentre dans while\n");
if ( (temp[compt]!=',') && (temp[compt]!='/') )
{
printf("on rentre dans 1er if\n");
nblu++;
}
if ( (temp[compt]==',') || (temp[compt]=='/') )
{
printf("on rentre dans 2ème if\n");
for(k=compt-nblu;k<compt;k++)
{
nblu--;
buffer=temp[k];
n = strtol (buffer, NULL, 10);
printf("on converti buffer vers n\n");
printf(" n vaut %d\n",n);
nb=nb+(n*puissance(10,nblu));
printf(" nb vaut %d\n",nb);
}
printf("valeur de nbl %d\n",nbl);
printf("valeur de nbc %d\n",nbc);
mat->tab[nbl][nbc]=nb;//l erreur est ici
//printf("%d\n",nb);
nb=0;
nbc++;
}
if (temp[compt]=='/')
{
nbl++;
(*mat).nbl=nbl;
nbc=0;
}
compt++;
}
return mat;
} |
Partager