-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumCad.c
More file actions
37 lines (33 loc) · 832 Bytes
/
NumCad.c
File metadata and controls
37 lines (33 loc) · 832 Bytes
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
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#define NUMARGS 1
bool cadisnum(char *s);
int main(int argc, char **argv) {
// 1. Comprobar num parametros
if (argc == NUMARGS+1){
if (cadisnum(argv[1]))
printf("El valor del argumento es %d\n", atoi(argv[1]));
else{
printf("ERROR el argumento no es una cadena de números\n");
return -1;
}
}
else {
printf("Faltan argumentos. Uso, numcad CADENA\n");
return -1;
}
return 0;
// 2. Funcion(cadena), devuelve true si todo son dígitos
// 3. atoi(s)
// 4. imprimir, etc, ...
}
bool cadisnum(char *s){
for (int i = 0; i < strlen(s); i++) {
if (!isdigit(s[i]))
return false;
}
return true;
}