Skip to main content
Search
Search This Blog
Livecodo
Pages
Home
Courses
Blog
About us
More…
Share
Get link
Facebook
X
Pinterest
Email
Other Apps
March 28, 2024
Write a c program to reverse the individual word of a given string Explanation: input : Welcome To livecodo output: emocleW oT odocevil.
Online C Compiler IDE
Editor
#include
#include
void reverse_word(char* word) { int length = strlen(word); for(int i = 0; i < length / 2; i++) { char temp = word[i]; word[i] = word[length - i - 1]; word[length - i - 1] = temp; } } int main() { char str[100]; printf("Enter a string: "); fgets(str, sizeof(str), stdin); // read string including spaces str[strcspn(str, "\n")] = '\0'; // remove trailing newline character char* token = strtok(str, " "); while(token != NULL) { reverse_word(token); printf("%s ", token); token = strtok(NULL, " "); } return 0; }
Output
Popular Posts
March 26, 2024
Dynamic Memory allocation in C
May 18, 2024
Searching and sorting Algorithm in C