View all questions by vigneshwaran
#include<stdio.h>
#include<string.h>
main()
{
char str[50],revstr[50];
int i=0,j=0;
printf("Enter the string to be reversed : ");
scanf("%s",str);
for(i=strlen(str)-1;i>=0;i--)
{
revstr[j]=str[i];
j++;
}
revstr[j]='\0';
printf("Input String : %s",str);
printf("\nOutput String : %s",revstr);
getch();
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char str[10],temp;
int i,len;
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
temp=str[i];
str[i]=str[len];
str[len--]=temp;
}
printf("%s",str);
getch();
}
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
char *str;
int i,len;
//not using any temp variable and assume we can use only string array and length
printf("Enter String : ");
scanf("%s",str);
len=strlen(str)-1;
for(i=0;i<strlen(str)/2;i++)
{
str[i]+=str[len];
str[len]=str[i]-str[len];
str[i]=str[i]-str[len--];
}
printf("Reverse String is : %s",str);
getch();
}
Answered On : Mar 14th, 2006
Can u pls guide me to reverse a string using recursion without using assignment operator.Thanking Uma
Answered On : Apr 17th, 2006
can u send me the program to reverse a string using recursion.And the input should be a list of characters i.e not getting the input as string.
Answered On : May 13th, 2006
How to write a c program to reverse the string with in the same string? I.e No other string variables should be used. Not even built functions also.
Answered On : Jul 4th, 2006
program to reverse a string using recursive function:
---------------------------------------------------
void reverse (int index, char *str ) ;
int main (void)
{
char name[100];
printf ("Enter a mutli-word string") ;
gets(name) ;
reverse (strlen(name) , name ) ;
}
void reverse (int index, char *str )
{
if (--index < 0 )
{
return ;
}
else
{
putchar ( *(str + index) ) ;
reverse (index, str) ;
}
}
Logic:
-----
For eg : let's say the user has entered 50 characters.
then index is initially 50.
when reverse() function is called for the first time then
index will be 50 .we first decrement the index by 1 so that
it will become 49 and i am printing the 49th character i.e last
character in the string then reverse() function is called again
with index as 49 and str pointing to 49th character and again
the index will be decremented by 1 so that it will become 48 this
will continue until zeroth index is reached.
i hope this will solve the problem that you have reported , for any
queries you can mail me.
Regards,
Syed
Answered On : Jul 29th, 2006
#include<stdio.h>
int main()
{
char c;
c=getchar();
if(c!='.') //dot is to terminate when u r finished given the string char by char/
main();//calling main recursively
putchar(c);
return 0;
}
Answered On : Aug 13th, 2006
Excellent code, Please give the solution for this RE: Write a C program to reverse the string by taking single char i.e by putting each time to that char
Answered On : Sep 23rd, 2006
not really a C programmer.pseudocode:String reverse(str){ if(str.length == 1){ return str; }else{ return(reverse(secondHalfOfString) + reverse(firstHalfOfString)) }}
Answered On : Oct 11th, 2006
void ret_str(char* s){ if(*s != ' ') ret_str(s+1); cout<<*(s);}int main(){ ret_str("born2c0de"); return 0;}~
Answered On : Oct 14th, 2006
I have written this code:
#include <stdio.h>
void rev_str(char* s)
{
if(*s != ' ')
rev_str(s+1);
printf("%c",*s);
}
int main()
{
rev_str("born2c0de");
return 0;
}
Here i am able to reverse the string and print it out...but i want rev_str function to return the reversed string or ideally reverse the passed string itself.
Can you help me out?
Answered On : Oct 17th, 2006
this is the program to revers the string without using string functions.
main()
{
int i,k,t,j;
char s1[20],s2[20];
printf("enter the stringn");
gets(s);
for(i=0;s[i]!=' ';i++)
{
j++;
}
t=0;
for(k=j;k>=0;k--)
{
s2[t]=s1[k];
t++;
};
s2[t]=' ';
printf("%s",s2);
}
Answered On : Dec 17th, 2006
#include
Answered On : Jul 4th, 2007
1. Write a function to reverse string.
int main()
{
char a[10] = "mysore" ;
char b[10];
strrev(a , b);
printf("%s",b); //should print "erosym"
}
2. Write a function to capitalize first letter of every word
in string.
int main()
{
char a[50] = "mysore karnataka india" ;
char b[50];
Capitalize(a , b);
printf("%s",b); //should print "Mysore Karnataka India"
}
3. Write a function to reverse the words in string.
int main()
{
char a[50] = "mysore karnataka india" ;
char b[50];
reversewords(a , b);
printf("%s",b); //should print "india karnataka mysore"
}
Answered On : Jul 4th, 2007
View all questions by soorajsk_84 View all answers by soorajsk_84
void main()
{
char str1[20],strev[20]
int *i=str1;
int *j=strev;
printf("Enter the srting");
scanf("%s",str1);
while(*i!= '
