#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
void rev_word(char line[]);
int
main(void)
{
char
*in_buf = NULL;
size_t buf_len = 0;
ssize_t str_len;
if
((str_len = getline(&in_buf, &buf_len, stdin)) != -1) {
rev_word(in_buf);
printf("%s", in_buf);
}
/*
* free buffer allocated by getline()
*/
free(in_buf);
in_buf = NULL;
return(EXIT_SUCCESS);
}
/*
* rev_word
*
*
Reverses the characters of each word in a string in place
*
All whitespace is preserved!
*
* library use: isspace() to test if char is
whitepsace
*
* input:
text string
* return:
none
*/
string reverses(string
str)
{
// Mark spaces in result
int n =
str.size();
string result(n, '\0');
for (int i = 0; i < n; i++)
if
(str[i] == ' ')
result[i] = ' ';
// Traverse input string from beginning
// and put characters in result from end
int j = n
- 1;
for (int i = 0; i < str.length(); i++) {
// Ignore spaces in input string
if
(str[i] != ' ') {
// ignore spaces in result.
if
(result[j] == ' ')
j--;
result[j] = str[i];
j--;
}
}
}
return result;
void
rev_word(char
line[])
{
return;
}
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
311 Experts Online