Razor, I already implemented something similar in Compiler discipline, a bit more complex because the text was in written form (eg "three hundred and twenty-three thousand, two hundred and fifty-four plus fifteen times two"). For this implementation I used the Java language with the help of Jflex it is a lexical analyzer. Follow the main code, I hope it helps.
LineTerminator = \r|\n|\r\n
WhiteSpace = {LineTerminator} | [ \t\f]
Number = [:digit:] [:digit:]*
pzero = "zero"
unidades = "um" | "dois" | "tres" | "quatro" | "cinco" | "seis" | "sete" | "oito" | "nove"
dezena = "onze" | "doze" | "treze" | "quatorze" | "quinze" | "dezesseis" | "dezessete" | "dezoito" | "dezenove"
dezenas = "vinte" | "trinta" | "quarenta" | "cinquenta" | "sessenta" | "setenta" | "oitenta" | "noventa"
pcem = "cem" | "duzentos" | "trezentos" | "catorze" | "quatrocentos" | "quinhentos" | "seiscentos" | "setecentos" | "oitocentos" | "novecentos"
centenas = "cento" | "duzentos" | "trezentos" | "quatrocentos" | "quinhentos" | "seiscentos" | "setecentos" | "oitocentos" | "novecentos"
dezuni = {dezenas}(" e "{unidades})
centdezuni = {centenas}( " e "{dezuni}) | {centenas}( " e "{dezenas}) | {centenas}( " e "{unidades}) | {centenas}( " e "{dezena})
juntos = {unidades} | {dezena} | {pcem} | {dezuni} | {centdezuni}
unidadedemilhar = {juntos}( " mil")( " , " {dezenas})*( " e " {unidades})*
| {juntos}( " mil")( " , " {pcem})
| {juntos}( " mil")( " , " {centdezuni})
{WhiteSpace}+ { /* ignore */ }
<YYINITIAL> {
{juntos} { return newToken(Terminals.NUMBER, new String(yytext())); }
{centdezuni} { return newToken(Terminals.NUMBER, new String(yytext())); }
{dezuni} { return newToken(Terminals.NUMBER, new String(yytext())); }
{pzero} { return newToken(Terminals.NUMBER, new String(yytext())); }
{pcem} { return newToken(Terminals.NUMBER, new String(yytext())); }
{dezenas} { return newToken(Terminals.NUMBER, new String(yytext())); }
{dezena} { return newToken(Terminals.NUMBER, new String(yytext())); }
{centenas} { return newToken(Terminals.NUMBER, new String(yytext())); }
{unidadedemilhar} { return newToken(Terminals.NUMBER, new String(yytext())); }
"(" { return newToken(Terminals.LPAREN); }
")" { return newToken(Terminals.RPAREN); }
"vezes" { return newToken(Terminals.MULT); }
"dividido" { return newToken(Terminals.DIV); }
"mais" { return newToken(Terminals.PLUS); }
"menos" { return newToken(Terminals.MINUS); }
}
In short, to facilitate your work, use some lexical analyzer, I know there are some libraries for C. Any questions you can contact.