einstein Posted April 21, 2012 at 03:59 PM Report #450407 Posted April 21, 2012 at 03:59 PM Eu quero fazer uma função que recebe como argumento um mes e escreve-o numa string o código que fiz foi o seguinte: #include<stdio.h> #include<stdlib.h> enum mes {Janeiro, Fevereiro, Marco, Abril, Maio, Junho, Julho, Agosto, Setembro, Outubro, Novembro, Dezembro}; typedef enum mes mes; int mes_str(mes m, char str[100]){ switch (m){ case 0: sprintf(str,"Janeiro\n"); break; case 1: sprintf(str,"Fevereiro\n"); break; case 2: sprintf(str,"Março\n"); break; case 3: sprintf(str,"Abril\n"); break; case 4: sprintf(str,"Maio\n"); break; case 5: sprintf(str,"Junho\n"); break; case 6: sprintf(str,"Julho\n"); break; case 7: sprintf(str,"Agosto\n"); break; case 8: sprintf(str,"Setembro\n"); break; case 9: sprintf(str,"Outubro\n"); break; case 10: sprintf(str,"Novembro\n"); break; case 11: sprintf(str,"Dezembro\n"); break; } } Não existe nenhuma forma de simplificar isto?
petvetbr Posted April 21, 2012 at 04:50 PM Report #450415 Posted April 21, 2012 at 04:50 PM É isto mesmo. Existem jeitos de fazer sem precisar do switch como criar um array com strings de todos os meses e depois acessar pelo índice: Ex. mes= meses[numeromes] Fernando Lage Bastos - MCP/MCTS/MCPD
einstein Posted April 21, 2012 at 11:07 PM Author Report #450466 Posted April 21, 2012 at 11:07 PM É isto mesmo. Existem jeitos de fazer sem precisar do switch como criar um array com strings de todos os meses e depois acessar pelo índice: Ex. mes= meses[numeromes] Ok.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now