22.10.2014 Views

Aprendendo a Programar Programando em Linguagem C - FSM

Aprendendo a Programar Programando em Linguagem C - FSM

Aprendendo a Programar Programando em Linguagem C - FSM

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

int i, d, m, a, Verifica;<br />

char Dia[3], Mes[3], Ano[5];<br />

strncpy(Dia, s, 2);<br />

Dia[3] = '\0';<br />

strncpy(Mes, s + 3, 2);<br />

Mes[3] = '\0';<br />

strcnpy(Ano, s + 6, 4);<br />

Ano[4] = '\0';<br />

d = atoi(Dia);<br />

m = atoi(Mes);<br />

a = atoi(Ano);<br />

Verifica = 1;<br />

if ((m = 1) && (d >= 1) && (d 29)<br />

Verifica = 0;<br />

else;<br />

else<br />

if (d > 28)<br />

Verifica = 0;<br />

break;<br />

case 4: case 6: case 9: case 11:<br />

if (d > 30)<br />

Verifica = 0;<br />

break;<br />

}<br />

else<br />

Verifica = 0;<br />

return(Verifica);<br />

}<br />

Vale observar que os comandos Verifica = 0 poderiam ser substituídos por return(0). Neste caso, o<br />

último comando seria return(1).<br />

7. Os compiladores C ignoram espaços <strong>em</strong> branco digitados num programa. Uma maneira de se tornar<br />

isto possível é, antes da compilação, eliminar todos os espaços <strong>em</strong> branco "supérfluos", ou seja, deixar duas<br />

palavras s<strong>em</strong>pre separadas por um único espaço <strong>em</strong> branco. A função abaixo, utilizando a função<br />

DeletaCaracteres(), realiza tal ação.<br />

void ExcluiBrancosSuperfluos(char *s)<br />

{<br />

int i, NumBrancos;<br />

i = 0;<br />

while (s[i] != '\0')<br />

{<br />

NumBrancos = 0;<br />

while (s[i] == ' ')<br />

{<br />

NumBrancos = NumBrancos + 1;<br />

i = i + 1;<br />

}<br />

if (NumBrancos > 1)<br />

{<br />

i = i - NumBrancos;<br />

DeletaCaracteres(s, NumBrancos - 1, i);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!