pgm to reverse string using arrays i.e god is love becomes
love is god)
(assumption:only space is used for seperation of words)
no addtional memory used.i.e no temporary arrays can used.
Answers were Sorted based on User's Feedback
#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,length;
char a[] = "god is love";
length = strlen(a);
printf("The Given String is\n%s\n",a);
printf("The Resulted String is\n");
for(i=length-1;i>=0;i--)
{
if(a[i] == ' ')
{
for(j=i+1; a[j] != ' ' && a[j] != '\0';j++)
{
printf("%c",a[j]);
}
printf("%c",a[i]);
}
}
i++;
while(a[i] !=' ')
{
printf("%c",a[i]);
i++;
}
printf("\n");
}
Is This Answer Correct ? | 14 Yes | 2 No |
Answer / abdur rab
#include <stdio.h>
void reverse_string ( char* cp_string, int start, int end )
{
if ( cp_string && ( start < end ) ) {
*( cp_string + start ) ^= *( cp_string +
end )
^= *( cp_string + start ) ^= *(
cp_string + end );
reverse_string ( cp_string, ++start, --
end );
}
}
int main ( int argc, char* argv [] )
{
char ca_array [12]={"Hello World"};
char* cp_ptr = NULL;
char* cp_ptr_temp = NULL;
printf ( "\n Before Reverse :%s", ca_array );
reverse_string ( ca_array, 0, strlen ( ca_array ) -
1 );
cp_ptr_temp = cp_ptr = ca_array;
while ( NULL != ( cp_ptr_temp = (char*) strchr (
cp_ptr_temp, ' ' ) ) ) {
reverse_string ( cp_ptr, 0, ( cp_ptr_temp -
cp_ptr ) - 1 );
cp_ptr = ++cp_ptr_temp;
}
// change the final word
reverse_string ( cp_ptr, 0, ( ( strlen (
ca_array ) - 1 ) - ( cp_ptr - ca_array ) ) );
printf ( "\n After Reverse by Words :%s",
ca_array );
return ( 0 );
}
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int i=0,c;
char a[20];
printf("\nEnter the string");
while((a[i++]=getchar())!='\n');
printf("\nReverse of the string is ");
for(c=i;c>=0;c++)
{
printf("%c"a[c]);
}
getch();
}
Is This Answer Correct ? | 1 Yes | 5 No |
Answer / paaru
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20],i;
printf("\n\nEnter the string:");
gets(a);
for(i=strlen(a)-1;i>=0;i++)
{
printf("%d"a[i]);
}
getch();
}
Is This Answer Correct ? | 1 Yes | 7 No |
64/square(4)
Hai why 'c' is the middle language
Hi Every one......... Please Any body give me the answer for my question. Is it possible to print the word "PRINT F", without using printf() statement in C-Language.
accept character from keyboard untill the user presses the enter key.If the user enters any character other than upper case(A-Z)alphabets program should stop taking any input
write a C code to reverse a string using a recursive function, without swapping or using an extra memory.
9 Answers Motorola, TCS, Wipro,
What is the process to generate random numbers in c programming language?
what is data structure?
write a program to concatenation the string using switch case?
3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r
char p="data"; printf(p);
Concat two string with most overlapped substring has to removeĀ "abcd"+ "cdef" = "abcdef
How can I find out if there are characters available for reading?