#include <stdio.h>
#include <string.h>
#define MAX_LEN 200
/*
This function will reverse the input string,
i.e content of word.
*/
void reverse_word(char *word, int len)
{
char *first, *last, temp;
first = word;
last = word + len - 1;
while (last > first) {
temp = *first;
*first = *last;
*last = temp;
last--;
first++;
}
}
int main()
{
char input_str[MAX_LEN]; //max of 200 char.
char buff[MAX_LEN];
char *ptr, *token, *delim = " ";
int len;
printf("Please enter the string which you want to convert :\n");
fgets(input_str, 200, stdin);
input_str[strlen(input_str) - 1] = '\0'; // for removing the new line (\n) character.
memset(buff, 0 , 200);
ptr = buff;
// it will extract token from the input_str, for more info see "man 3 strtok"
token = strtok(input_str, delim);
while (token != NULL) {
len = strlen(token);
if (!isdigit(*token)) {
reverse_word(token, len);
}
strncpy(ptr, token, len);
ptr[len] = ' ';
ptr = ptr + len + 1;
token = strtok(NULL, delim);
}
printf("output : %s\n", buff);
return 0;
}