Bien coder en C : avis sur bout(s) de code
Bonjour,
Je mettrai ici de temps en temps des bouts de code issus du programme que je suis en train de faire dans le but d'avoir des retours critiques sur la "propreté" de mon code.
Est-ce bien codé ? Tant sur la forme que sur le fond. Le but est de prendre les bons réflexes et d'éviter les mauvaises habitudes.
Je commence par cette fonction :
Code:
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
| int get_handlepath(char path[])
{
int i_path;
int i_handle;
int i_found;
int i_subpath;
for (i_path = 0; i_path < compter_ch(path); i_path++)
{
if (path[i_path] == '\\')
{
i_found = i_path;
i_path = 0;
if ((t_registre.handle = (char*)malloc((i_found+1)*sizeof(char)))
&& (t_registre.path = (char*)malloc((compter_ch(path)-i_found)*sizeof(char))) != NULL)
{
for (i_handle = 0; i_handle < i_found; i_handle++)
{
t_registre.handle[i_handle] = path[i_path];
i_path++;
}
t_registre.handle[i_found] = '\0';
i_subpath = 0;
for (i_found = i_found+1; i_found < compter_ch(path); i_found++)
{
t_registre.path[i_subpath] = path[i_found];
i_subpath++;
}
t_registre.path[i_subpath] = '\0';
return (0);
break;
}
}
}
return (1);
} |
Merci par avance.
;)