Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi,
i want to know the how to write a c program to reverse a string without using string.h and its function.
I knew that program as i did it in college last year but now i dont remeber that so i need ur help

#include <stdio.h>
#include "reverse.h"/****************************************************************/
reverse (before, after)
char *before; /* A pointer to the original string */
char *after; /* A pointer to the reversed string */{
int i;
int j;
int len;len = strlen (before);
for (j = len - 1, i = 0; j >= 0; j--, i++) /* Reverse loop */
after[i] = before[j];after[len] = NULL; /* NULL terminate reversed string */
}jim partner
experts in reseller hosting
http://www.cpwebhosting.net

// here is a simple program to reverse a string
#include<stdio.h>
#include<string.h>#define SIZE 20 //macro for size of
//stringvoid main()
{
char str[SIZE]; //stores the string
int length; //keeps track of
//length of string
printf("enter string: ");
gets(str);
len=strlen(str); //strlen(str)
//returns length of
//string
for(int i=len-1;i>0;i--)
printf("%c"str[i]);}
//by wasif

![]() |
Decimal - > Binary in sch...
|
reading from a file
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |