CoolInterview.com - World's Largest Collection of Interview Questions
Send Free SMS
 Interview Questions  
 Our Services  


INTERVIEW QUESTIONS LANGUAGES C DETAILS
Question :
If a string variable contain "i am a good boy" then how a c program will print "boy good a am i".?

Posted by: Dheeraj sharma on 1/14/2008

Contact Dheeraj sharma  Contact Dheeraj sharma
Category C Interview Questions
Rating (5.0) By 1 users
Added on 1/14/2008
Views 1928
Rate it!
Answers:

The string reverse can be done by using the string reverse function.
That is the "strrev" function.



 Posted by: santosh kumar pandi    

Contact santosh kumar pandi  Contact santosh kumar pandi

void str_reve_word(char* str)
{
int length = strlen(str);
int i=0;
while(length>=0)
{
if(str[length]!=' ')
{
length--;
continue;
}
for(i=length+1;((str[i]!=' ')&&(str[i]!='



 Posted by: sha    

Contact sha  Contact sha

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


int main(int argc, char *argv[])
{
char *mesg = " I am a good boy. ";
char *startPtr, *endPtr, *tmpPtr;
endPtr = startPtr = mesg+strlen(mesg)-1;
while(startPtr > mesg) {
if(isgraph(*startPtr)) {
startPtr--;
}
else
{
tmpPtr = startPtr+1;
while(tmpPtr <= endPtr)
{
putchar((int)*tmpPtr);
tmpPtr++;
}
putchar((int)*startPtr);
startPtr--;
endPtr = startPtr;
}
}
tmpPtr = startPtr;
while(tmpPtr <= endPtr)
{
putchar((int)*tmpPtr);
tmpPtr++;
}
return 0;
}



 Posted by: Akhilesh Shirbhate    

Contact Akhilesh Shirbhate  Contact Akhilesh Shirbhate

void main()
{
int l[100],n;
char str[5][20];
printf("How many strings")
scanf("%d",&n);
//read the string//
for(i=0;i<n;i++)
{
printf("Enter the %d string",i+1);
fflush(stdin);
scanf("%s",str[i]);
}
//calculate the length of each string//
for(i=0;i<n;i++)
{
l[i]=strlen(str[i]);
}
for(i=n;i>=0;i--)
{
for(j=0;j<l[i];j++)
{
printf("%s",str[i][j]));

getch();
}
}



 Posted by: Udhaya banu.N    

Contact Udhaya banu.N  Contact Udhaya banu.N

#include<iostream>

using namespace std;


char * revCopy(const char* );


int main(){

char *abc = "i am a good boy";

cout<<"the retruned copy is "<<revCopy(abc);

}


char * revCopy(const char *str){


char * abc = new char[strlen(str) + 1];
int iAbc = 0;

//strcpy(abc,str);

for(int i=strlen(str) - 1;i >= -1;i--){

if(str[i] == ' ' || i == -1 ){

for(int j = i+1;j < strlen(str) && str[j] != ' ';j++){

abc[iAbc++] = str[j];
}

abc[iAbc++] = ' ';
}
}

abc[iAbc] = '



 Posted by: Vaibhav    

Contact Vaibhav  Contact Vaibhav

This is nothing but the string reversal.

Declare a variable x as string .
use " strrev() "
function to get the result U like for any string .

Note: You have to declare
#include<string.h>
at the begining of the program.



 Posted by: kalavnagarjuna    

Contact kalavnagarjuna  Contact kalavnagarjuna

void main()
{
char ch[8][20];
printf("Enter a string:and $for end of the string ");
for (int i = 0; i < 8; i++)
{
scanf("%s", ch[i]);
if(ch[i][0] == '$')
break;
}

for (i--; i >= 0; i--)
printf("%s ", ch[i]);

}



 Posted by: Biplab    

Contact Biplab  Contact Biplab

#include <stdio.h>
#include <string.h>
int main()
{
char in_str[16] = "I am a good boy";
char out_str[16] = {0};
char current_letter = 0;
int str_len = 0;
int in_str_pos = 0;
int temp_in_str_pos = 0;
int out_str_pos = 0;
int letter_count = 0;

/* calculate the string len */
str_len = strlen(in_str);
in_str_pos = str_len-1;
out_str_pos = 0;

while (in_str_pos >= 0)
{
if(in_str[in_str_pos] != ' ') /* If the letter is not a space */
{
letter_count++;
in_str_pos--;
}
else /* If the letter is a space */
{
/* put the word in correct order to the output string */
temp_in_str_pos = in_str_pos+1;
while (letter_count)
{
out_str[out_str_pos] = in_str[temp_in_str_pos];
letter_count--;
out_str_pos++;
temp_in_str_pos++;
}
/* Add space to the output string */
out_str[out_str_pos] = ' ';
out_str_pos++;
in_str_pos--;
}
}
/* For last word - in this case "I" */
temp_in_str_pos = in_str_pos+1;
while (letter_count)
{
out_str[out_str_pos] = in_str[temp_in_str_pos];
letter_count--;
out_str_pos++;
temp_in_str_pos++;
}

/* put "end of string" to output string */
out_str[out_str_pos] = '



 Posted by: Aneeb    

Contact Aneeb  Contact Aneeb

using strrev() function we can reversed that string
#include<stdio.h>
#include<string.h>
void main()
{
char a[20];
printf("
Enter the string:");
scanf("%s",&a);
strrev=strrev(a);
printf("
The reversed string is:%s,sttrrev);
}



 Posted by: asha    

Contact asha  Contact asha

char res_str1[10][10];
char in_str[100];
char *tmp_str;
int len,i;

strcpy(in_str,"i am a good boy");
printf("Input string:- %s
", in_str);

tmp_str = strtok(in_str, " ");
i = 0;
while(tmp_str != NULL) {
strcpy(res_str1[i],tmp_str);
tmp_str = strtok(NULL, " ");
i++;
}

printf("Reversed String:- ");
i--;
while (i >= 0) {
printf("%s ", res_str1[i]);
i--;
}



 Posted by: Lakshmi    

Contact Lakshmi  Contact Lakshmi


If you have the better answer, then send it to us. We will display your answer after the approval.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification  Enter the above shown code:*
Inform me about updated answers to this question

   
Related Questions
View Answer
Write a Program to convert decimal to binary no.
View Answer
Can anyone share his code which would accept a sentence, then count the number occurrence of the words excluding spaces.All is done using linked list.
View Answer
using c-strings write a program that will analyse the text"1.1my brother is taller than me.1.2 I am a boy of sixteen years old". The program should remove multiple spaces betweem words,find the longest word in the text,search and identify the number of letters"e", extact the number of integers , extract the number of doubles, extract the number of words in each sentence and identify the number of sentences in the text.
View Answer
How do I use c-strings to write a c program that Removes multiple spaces between words in a paragraph?
View Answer
Write A Program With Out Using ;
View Answer
What are the applications and advantages of C-language?
View Answer
A variable carries a value.(already assigned OR from Scanf..what ever the way). I want to know whether the variable is positive or negative.
Conditions:
-----------
1.NO looping logic should be used such as for ..while..etc.

2.should not use > or <.

3.should not use any numbers except 0.
We can use 0 and equality operator.
How to know the number is positive or negative?
View Answer
Define structural language and procedural language?
View Answer
Q.8 When a 'C' function call is made, the order in which parameters passed to the function are pushed into the stack is
(a) left to right
(b) right to left
(c) bigger variables are moved first than the smaller variables.
(d) smaller variables are moved first than the bigger ones
(c) none of the above.
View Answer
how do i get started for any project?
View Answer

Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.

Notify me when better answer is posted!
Email:

View ALL C Interview Questions

User Options
Sponsored Links


Copyright ©2003-2010 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions
Page URL: http://www.coolinterview.com/interview/12735/default.asp?cachecommand=bypass


Download Yahoo Messenger | Placement Papers| FREE SMS | ASP .Net Tutorial | Web Hosting | Free SMS | Dedicated Servers | Joke of the Day

0.72