int main() {
if (/*your code goes here*/) {
printf("hello");
} else {
printf("world");
}
return 0;
}
Try printing "helloworld" by just filling in the condition in the if statement ?
Hint:
Ever wondered what printf returns? ;)
int main() {
if (/*your code goes here*/) {
printf("hello");
} else {
printf("world");
}
return 0;
}
Here's the problem:
enum
{
SUCCESS,
FAILURE
};
int
reverse(char *in, unsigned int start_index,
unsigned int end_index)
{
char temp;
if (in == NULL || start_index > end_index)
return (FAILURE);
while (start_index < end_index) {
temp = in[start_index];
in[start_index] = in[end_index];
in[end_index] = temp;
start_index++;
end_index--;
}
return (SUCCESS);
}
int
rotate_string(char *rotate_me, unsigned int times,
unsigned int is_clockwise)
{
unsigned int len = 0;
if (rotate_me == NULL)
return (FAILURE);
//initialize the length;
len = strlen(rotate_me);
//if times > len, fix it.
times %= len;
//fix if rotation needs to be clockwise
if (times != 0 && is_clockwise) {
times = len - times;
}
/*
* First, reverse the times - 1 characters.
* Now, reverse times to len - 1
* Finally, reverse the whole string.
*/
if (times > 0 &&
(
reverse(rotate_me, 0, times - 1) == FAILURE ||
reverse(rotate_me, times, len - 1) == FAILURE ||
reverse(rotate_me, 0, len - 1) == FAILURE
)
) {
return (FAILURE);
}
return (SUCCESS);
}