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 9209115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:45:58+00:00 2026-06-18T00:45:58+00:00

I’m trying to do a couple simple implementations of string_reverse in C. However, I

  • 0

I’m trying to do a couple simple implementations of string_reverse in C. However, I get the following error when I debug in gdb:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004005ca in string_reverse1 (string=0x68 <Address 0x68 out of bounds>)
28          length = strlen(*string);
Missing separate debuginfos, use: debuginfo-install glibc-2.15-58.fc17.x86_64

Here’s my code for the error I’m getting (I commented on the line where the error comes from):

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

int main(int argc, char *argv[])
{
    char *char1 = "hello";
    char *char2 = "hi";
    char *char3 = "this is a really long string!";

    string_reverse1(*char1);
    string_reverse1(*char2);
    string_reverse1(*char3);
    printf("%s, %s, %s\n", char1, char2, char3);

    return 0;
}

//Assuming method's purpose is to reverse the passed string
//and set the original string equal to the reversed one
void string_reverse1(char *string) 
{
    //Calculate length once so it isn't recalculated at
    //every iteration of the for loop
    int length;
    char *reversed;
    int i;
    int reversed_counter;
    length = strlen(*string); //ERROR
    reversed_counter = 0;
    for(i = length - 1; i >= 0; i--) {
        reversed[reversed_counter] = string[i];
        reversed_counter++;
    }
    //Can't forget to add the terminating null character!
    reversed[length] = '\0';
    string = reversed;
}

I know that strlen returns the length of a passed string by advancing through the string until it lands on \0, the null byte. So I’m wondering if perhaps the string passed is somehow not null-terminated? I don’t think I declared the strings incorrectly in main though.

Thanks for any insight.

  • 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-18T00:45:59+00:00Added an answer on June 18, 2026 at 12:45 am

    The problem is when you call string_reverse1:

    string_reverse1(*char1);
    

    The * before char1 dereferences char1 returning the value of the first character of the string. If you want to pass the *char you should just omit the *. This is because the type of char1 is already char *. There’s no need to change it.

    When you dereference char1 you’re sending the actual ascii value of the first character, ‘h’. Then strlen is attempting to access the memory at address ‘h’ and segfaulting because that’s just some arbitrary memory location.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.