• 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

Given Set of words or A String find whether chain is possible from these words or not

Handle duplicates in Binary Search Tree

VMWare SDEII Interview

Convert Decimal to Roman numbers / Romanizer HackerEarth Code

Interfaces in C++ (Abstract Classes in C++)

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

Adobe Interview Questions 8 month Exp

25 horses 5 tracks Find 3 fastest puzzle

Code Chef PRGIFT Solution

Find and print longest consecutive number sequence in a given sequence in O(n)

CodeChef’ RRCOPY

In Given LinkedList Divide LL in N Sub parts and delete first K nodes of each part

ADOBE Aptitude C Language Test

The Magic HackerEarth Nirvana solutions Hiring Challenge

Reliance Jio Software Developer Interview Experience

Linked List V/S Binary Search Tree

Add Sub Multiply very large number stored as string

SAP Off Campus Hiring_ March 2015 Computer Skills

Hackerearth : Counting Subarrays

Convert number to words java

Microsoft BING Interview Experience

Trapping Rain Water

Binary Tree Isomorphic to each other

Check if an array has duplicate numbers in O(n) time and O(1) space

Templates in C++

There are N nuts and N bolts, u have to find all the pairs of nuts and bolts in minimum no. of iteration

Wrong Directions given find minimum moves so that he can reach to the destination

Python Dictionaries

Knight Tour Problem (Graph – Breadth First Search)

How strtok() Works

Copyright © 2025 · Genesis Framework · WordPress · Log in