-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.c
More file actions
38 lines (31 loc) · 1.1 KB
/
3.c
File metadata and controls
38 lines (31 loc) · 1.1 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <regex.h>
char stringInteiro[] = "^[0-9]*$";
char stringReal[] = "^[0-9]+\\.[0-9]+$";
char stringSimbolo[] = "^[\\+|-|/|*|(|)|\\]*$";
void main(){
char stringOriginal[] ="( 2 + 6 ) - 7 * 7 / 35 + + 1..1";
char * stringSeparada;
stringSeparada = strtok (stringOriginal," ");
regex_t regexInteiro;
regex_t regexReal;
regex_t regexSimbolo;
regcomp(®exInteiro, stringInteiro, REG_EXTENDED);
regcomp(®exReal, stringReal, REG_EXTENDED);
regcomp(®exSimbolo, stringSimbolo, REG_EXTENDED);
printf ("%s\n",stringOriginal);
while (stringSeparada != NULL){
printf ("%s -> \t",stringSeparada);
if(regexec(®exInteiro, stringSeparada, 0, NULL, 0) == 0)
printf("Numero Inteiro\n");
else if(regexec(®exReal, stringSeparada, 0, NULL, 0) == 0)
printf("Numero Real\n");
else if(regexec(®exSimbolo, stringSeparada, 0, NULL, 0) == 0)
printf("Operação\n");
else
printf("Erro\n");
stringSeparada = strtok (NULL, " ");
}
}