Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8972479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:13:39+00:00 2026-06-15T18:13:39+00:00

Possible Duplicate: Reversing a string in C I’m currently switching from C++ to C

  • 0

Possible Duplicate:
Reversing a string in C

I’m currently switching from C++ to C programming for a project and I haven’t done much with Char arrays as strings. I need a function that will read in a pointer to a char array and reverse it. I wrote this in C++, which is pretty easy using the string functions, but I’m a little confused on if there are functions or something else in C that is the best way to do this. Thanks, and I’m not necessarily looking for someone to completely finish the code, but to point me in the right direction. If it’s simple one line something feel free, but don’t do anything that makes you feel uncomfortable.

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

void reverseString(char *myString)
{
    //reverse string here
}

int main(void)
{
    char myString[] = "This is my string!";
    reverseString(myString);

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:13:40+00:00Added an answer on June 15, 2026 at 6:13 pm

    Simplest way: Loop the string char by char and insert each char to another char array in the reverse order.

    Or try this:
    2)

    void reverse_string(char str[])
    {
        char c;
        char *p, *q;
    
        p = str;
        if (!p)
            return;
    
        q = p + 1;
        if (*q == '\0')
            return;
    
        c = *p;
        reverse_string(q);
    
        while (*q != '\0') {
            *p = *q;
            p++;
            q++;
        }
        *p = c;
    
        return;
    }
    

    3)

    if( strlen( str ) > 0 ) {
       char* first = &str[ 0 ];
       char* last = &str[ strlen( str ) - 1 ];
       while( first < last ) {
           char tmp = *first;
           *first = *last;
           *last = tmp;
          ++first;
          --last;
    

    4)

    char* strrev( char* s )
      {
      char  c;
      char* s0 = s - 1;
      char* s1 = s;
    
      /* Find the end of the string */
      while (*s1) ++s1;
    
      /* Reverse it */
      while (s1-- > ++s0)
        {
        c   = *s0;
        *s0 = *s1;
        *s1 =  c;
        }
    
      return s;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Reversing an MD5 Hash Given this method in c# public string CalculateFileHash(string
Possible Duplicate: Extracting dollar amounts from existing sql data? I have a column in
Possible Duplicate: std::string and its automatic memory resizing I am just curious, how are
Possible Duplicate: String equality vs equality of location public class AboutStrings{ public static void
Possible Duplicate: Problems with newline in Graphics2D.drawString String eol =System.lineSeparator(); String sampleText =epcURNText +eol+studentName+eol+DelayComments+eol+ArrivalMethodComments+eol;
Possible Duplicate: Reversing a regular expression in python I think I ran into a
Possible Duplicate: Java Strings and StringPool I created two Strings String s1=MyString; String s2=new
Possible Duplicate: Removing an activity from the history stack Suppose I have three activities
Possible Duplicate: In Perl, how can I check from which module a given function
Possible Duplicate: array_splice() for associative arrays How to add an array value to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.