Sunday, March 11, 2012

A c program for reversing the strings without using string functions

Many of my friends have asked me about a c program for reversing the words (strings) without any garbage values at the end of reversed words, so finally here it is:



#include<stdio.h>
#include<conio.h>
int main()
{
char a[100],b[100];
int count=0,i=0,c;
clrscr();
printf("enter a word : ");
gets(a);
for(i=0;a[i]!='\0';i++)
{
count++;
}
printf("\nthe number of letters in the entered letter is : %d\n",count);
c=count;
for(i=0;i<count;i++)
{
b[i]=a[c-i-1];
if(b[i]=='\0')
break;
}
for(i=0;i<count;i++)
{
printf("%c",b[i]);
if(b[i]=='\0')
{
break;
}
}
getch();
return 0;
}






thank you and feel free to comment and suggest.


No comments:

Comments

blog comments powered by Disqus