Code:
#include <stdio.h>
int main(int argc, char *argv[]){
int i,n;
for(i=argc-1;i>0;i--){
for(n=string_length(argv[i])-1;n>=0;n--){
printf("%c",argv[i][n]);
}
printf(" ");
}
if(argc<2){
printf("no argument given");
}
return 0;
}
Sorry swgh, but I like programming this kind of things
Oh, and with your functions:
Code:
#include <stdio.h>
int main(int argc, char *argv[]){
int i,n;
for(i=argc-1;i>0;i--){
reverse_string(argv[i]);
printf("%s ",argv[i]);
}
if(argc<2){
printf("no argument given");
}
return 0;
}
Was string_length() necessary, because it is not actually needed , there are two ways to do it, using reverse_string() to reverse the string or using string_length() to read it as reversed, which is a bit more complicated.
If you like the first one more you can just replace strlen() there with string_length(). //Edit: I already replaced it
The first one is a bit better because the arguments remain untouched but the second one reverses the arguments and you cannot use them normally after reversing them.
981st edit:
You needed to make these funcitons yourself?
Code:
int string_length(char *text){
int i;
for(i=0;text[i]!='\0';i++){}
return i;
}
void reverse_string(char *text){
int i=string_length(text),n,a;
char *temp=malloc(i+1);
for(n=0;text[n]!='\0';n++){
temp[n]=text[n];
}
for(a=0;a<i;a++){
text[a]=temp[i-a-1];
}
free(temp);
return;
}