• 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

Find two non repeating elements in an array of repeating elements

Given a float number convert it into the string WITHOUT using any inbuilt Function

Closed Parentheses checker

Client Server C program

Maximum of all subarrays of size k

Stock Buy Sell to Maximize Profit

Top 10 Interviews Techniqes for Campus Interview in IIT NIT BITS for MTech

Flipkart SDET Interview Experience

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

Level order traversal in Spiral form

Maximum occurred Smallest integer in n ranges

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

Given array of 0’s and 1’s. All 0’s are coming first followed by 1’s. find the position of first 1

SAP Off Campus Hiring_ March 2015 Sample Questions

Find if a binary tree is height balanced ?

Find Pythagorean Triplets in an array in O(N)

C Program for TAIL command of UNIX

Trapping Rain Water

Test Cases for Round Function

SAP Off Campus Hiring_ March 2015 Analytical Aptitude

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

Singly linked list

Common Ancestor in a Binary Tree or Binary Search Tree

Circular Linked List

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

Practo Hiring Experience

Stickler thief

Find the number ABCD such that when multipled by 4 gives DCBA.

Naurki.com Security Breach

Leetcode: Merge Intervals

Copyright © 2026 · Genesis Framework · WordPress · Log in