Computing.Net > Forums > Programming > reverse a string

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

reverse a string

Reply to Message Icon

Name: 1-2-3-4-5-6
Date: November 24, 2005 at 05:43:02 Pacific
OS: win xp sp2
CPU/Ram: 256
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: jimcpweb
Date: November 24, 2005 at 07:37:43 Pacific
Reply:

#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


0

Response Number 2
Name: chin2
Date: December 24, 2005 at 14:07:19 Pacific
Reply:

// here is a simple program to reverse a string

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

#define SIZE 20 //macro for size of
//string

void 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



0
Reply to Message Icon

Related Posts

See More


Decimal - > Binary in sch... reading from a file



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: reverse a string

Converting a String to a char array www.computing.net/answers/programming/converting-a-string-to-a-char-array/3190.html

Batch Extracting part of a string www.computing.net/answers/programming/batch-extracting-part-of-a-string/15641.html

trimming spaces in a string www.computing.net/answers/programming/trimming-spaces-in-a-string/1025.html