• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar
  • Skip to secondary sidebar

GoHired

Interview Questions asked in Google, Microsoft, Amazon

Join WeekEnd Online Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

  • Home
  • Best Java Books
  • Algorithm
  • Internship
  • Certificates
  • About Us
  • Contact Us
  • Privacy Policy
  • Array
  • Stack
  • Queue
  • LinkedList
  • DP
  • Strings
  • Tree
  • Mathametical
  • Puzzles
  • Graph

Printing each word reverse in string

July 29, 2014 by Dhaval Dave

Below is the code to print each word backward
Example if Input is “This is Sparta”
Out put should be  “sihT si atrapS”


Thanks to Dhaval for suggesting this approach

#include<stdio.h>
#include<string.h>

int main()
{
    int j,i; int lastWhiteSpace = 0; //there were no white spaces
    char str[100]="This is Sparta";
    printf("nString in Reverse Ordern");

    i=0;
    while(str[i]!='')
    {
        if(str[i]==' ')
        {
            for(j=i-1;j>=lastWhiteSpace;j--) printf("%c",str[j]);
//Loop starts from last char and decrements upto the character after the last white space 
            printf(" ");
            lastWhiteSpace = i + 1; 
//the character after this white space 
        }
        i++;
    }

    //later edit
    for(j=i-1;j>=lastWhiteSpace;j--)
        printf("%c",str[j]);
    printf("n");
}

Similar Articles

Filed Under: Adobe Interview Questions, Interview Questions, Microsoft Interview Questions, problem Tagged With: string

Reader Interactions

Primary Sidebar

Join WeekEnd Online/Offline Batch from 4-April-2020 on How to Crack Coding Interview in Just 10 Weeks : Fees just 20,000 INR

Join WeekEnd Online/Offline Batch from 4-April-2020

WhatsApp us

Secondary Sidebar

Custom Search

  • How I cracked AMAZON
  • LeetCode
  • Adobe
  • Amazon
  • Facebook
  • Microsoft
  • Hacker Earth
  • CSE Interview

Top Rated Questions

Generate largest number arranging a no. of given non negative integer numbers

Printing Longest Common Subsequence

building with N steps, we can take 1,2,3 steps calculate number of ways to reach at top of building

Reliance Jio Software Developer Interview Experience

Length of the longest substring without repeating characters

Edit Distance ( Dynamic Programming )

Find shortest distances between every pair of vertices ( Dynamic Programming Floyd Warshall Algorithm)

Python String and numbers

Find next greater number with same set of digits

Handle duplicates in Binary Search Tree

Diagonal Traversal of Binary Tree

Implement a generic binary search algorithm for Integer Double String etc

Search element in a matrix with all rows and columns in sorted order

Find the kth number with prime factors 3, 5 and 7

Binary Tree in Java

Test Cases for Round Function

robot standing at first cell of an M*N matrix. It can move only in two directions, right and down. In how many ways, it can reach to the last cell i.e. (M, N) Code it

Hackerearth : Counting Subarrays

N teams are participating. each team plays twice with all other teams. Some of them will go to the semi final. Find Minimum and Maximum number of matches that a team has to win to qualify for finals ?

Common Ancestor in a Binary Tree or Binary Search Tree

TicTacToe Game As Asked in Flipkart

Binary Tree in Java

Flipkart Set 1 On Campus with Answers

Practo Hiring Experience

Add Sub Multiply very large number stored as string

Print vertical sum of all the axis in the given binary tree

HackeEarth Flipkart’s Drone

1014 Practice Question of New GRE – Princeton

Generic Object Oriented Stack with Template

Maximum path sum between two leaves

Copyright © 2026 · Genesis Framework · WordPress · Log in