This commit is contained in:
Geoffrey Frogeye 2016-03-09 09:41:56 +01:00
parent d8e509a1aa
commit a6707b6a78

38
TP3/E6.c Normal file
View file

@ -0,0 +1,38 @@
/* Conversion chaîne de caractères en entier */
#include <stdio.h>
#include <math.h>
#define N 10
int length(char* c) {
int i, len = -1;
for (i = 0; i < N; i++) {
if (c[i] == '\0') {
len = i;
break;
}
}
return len;
}
int number(char c) {
return c-48;
}
int atoiMaison(char* c) {
int i, len = length(c), n = 0;
for (i = 0; i < len; i++) {
n += number(c[i]) * (int) pow(10, len - i - 1);
}
return n;
}
int main() {
char c[N];
printf("Entrez un nombre entier : ");
scanf("%s", &c);
printf("Vous avez entré : %d\n", atoiMaison(c));
return 0;
}