Home Basic Loop Array string Function Pointer Contact STUDY

AHF    C    PROGRAM    SOLVING

Programming tips

" ; " after loop



Header file



Test expression



Comment



Specifer




String_ word by word reveres of a string




// AHF C PROGRAM SOLVING

//solving here 2_D   ARRAY 	programming problem

#include #include #define pf printf #define MAX_SIZE 100 // Maximum string size for all int main() { char str[1000], rev[100]; int length, i, index, word_start, word_end; //input data pf("Enter any string: "); gets(str); //taking length of the given string length= strlen(str); index = 0; //initialing index variable // start checking of words from the end of string word_start = length - 1; word_end = length - 1; while(word_start > 0) { // If a word is found if(str[word_start] == ' ') { // add the word to the reverse string i = word_start + 1; while(i <= word_end) { rev[index] = str[i]; i++; //update second loop index++; //update index value } rev[index++] = ' '; //taking space after reveres of each word word_end = word_start - 1; } word_start--; //update first while loop } // Finally add the last word for(i=0; i<=word_end; i++) { rev[index] = str[i]; index++; } //end of reverse string rev[index] = '\0'; pf("\nThe given string is: %s", str); pf("\nThe reverse word by word of the given string is: %s", rev); return 0; }
OUTPUT:


© 2018 - All rights reserved