benkas Posted May 6, 2008 at 01:34 PM Report Share #183587 Posted May 6, 2008 at 01:34 PM Boas!!! alguem me sabe dizer como juntar na mesma variavel varias string que sao inseridas na linha de comando? Exemplo: viva ao P@P char *frase="viva ao P@P" Link to comment Share on other sites More sharing options...
TheDark Posted May 6, 2008 at 02:09 PM Report Share #183592 Posted May 6, 2008 at 02:09 PM int main(int argc, char **argv) { int i, j=0; char *st; for (i=0; i<argc; ++i) { j += strlen(argv[i]); } st = (char *)malloc(sizeof(char) * i); *st = '\0'; for (i=0; i<argc; ++i) { strcat(st, argv[i]); strcat(st, " "); } /* st tem o valor de todos os argumentos concatenados */ return 0; } Não testei esse código, mas deve funcionar. Além de que é muito optimizável. Desaparecido. Link to comment Share on other sites More sharing options...
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