i've made my own copy of the tool "echo", this is not to improve it or anything, but only to learn about strings and pointers...
Code:
#include <stdio.h>
#include <strings.h>
#include <stdlib.h>
int main(int argc,char** argv[])
{
if(argc>1)
{
char *str[100];/*one array for every argument*/
char *str2=" ";
int loop=0;
int count=1;
while (loop<=argc)/*loop to copy every argument to a string[]*/
{
str[loop]=argv[count];
loop++;
count++;
}
for(loop=0;loop<argc-1;loop++)/*loop to print the strings with a space between them(just like they were entered)*/
{
printf("%s",str[loop]);
printf("%s",str2);
}
return 0;
}
return EXIT_FAILURE;
}
now the question: what can i do to improve this code? isn't there a possibility to read argv[1] as one complete string, even if a space is entered?