Nice, computer science homework.
int main () {
char str[]="this is my string";
//print our string forwards
int i = 0;
while(str[i]!="\0") {
putchar( str[i] );
i++;
}
//newline
putchar('\n');
//print our string backwards
int length = strlen(str);
while(length--) {
putchar( str[length] );
}
}
I didn't test this to make sure it worked, but this is the general way of doing this. It looks like your professor wants you to use pointers. I used pointers here. Do you know how? Arrays are pointers with some syntactic sugar.
I wouldn't rely on sites like this to get answers to your homework. Even if you get the right answer, there's always the possibility of your CS professor finding this answer online and then making your future homework ten times harder.
167 views
Usually answered in minutes!
×