This repository has been archived on 2019-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
s4-c/TP3/E6.c

38 lines
656 B
C
Raw Normal View History

2016-03-09 09:41:56 +01:00
/* Conversion chaîne de caractères en entier */
#include <stdio.h>
#include <math.h>
2016-03-09 11:10:07 +01:00
#define N 20
2016-03-09 09:41:56 +01:00
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) {
2016-03-09 11:10:07 +01:00
return c - '0';
2016-03-09 09:41:56 +01:00
}
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;
}