B
benoit.lefebvre
How can I join args from a function ?
Here is what I've done so far but I'm getting weird results
code:
------------8<--------------------------
#include<stdio.h>
int main (int argc, char *argv[])
{
int i;
int j;
char *allchars;
if (argv[1]) {
allchars = argv[1];
if (argv[2]) {
for (i = 2; i < argc; i++) {
printf("%i) Adding: \"%s\"\n",i, argv);
strcat(allchars, " ");
strcat(allchars, argv);
}
}
}
printf("All: \"%s\"\n", allchars);
return 0;
}
------------------------------------------
execution:
------------8<--------------------------
[mox@home (/home/mox)]: ./cnsudo Hi this is a test
2) Adding: "this"
3) Adding: "is"
4) Adding: "a"
5) Adding: "test"
All: "Hi is a test"
------------------------------------------
How come I am missing the second argument ? But the strcat works ???
Thanks,
--Benoit Lefebvre
(e-mail address removed)
Here is what I've done so far but I'm getting weird results
code:
------------8<--------------------------
#include<stdio.h>
int main (int argc, char *argv[])
{
int i;
int j;
char *allchars;
if (argv[1]) {
allchars = argv[1];
if (argv[2]) {
for (i = 2; i < argc; i++) {
printf("%i) Adding: \"%s\"\n",i, argv);
strcat(allchars, " ");
strcat(allchars, argv);
}
}
}
printf("All: \"%s\"\n", allchars);
return 0;
}
------------------------------------------
execution:
------------8<--------------------------
[mox@home (/home/mox)]: ./cnsudo Hi this is a test
2) Adding: "this"
3) Adding: "is"
4) Adding: "a"
5) Adding: "test"
All: "Hi is a test"
------------------------------------------
How come I am missing the second argument ? But the strcat works ???
Thanks,
--Benoit Lefebvre
(e-mail address removed)