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

  • Home
  • SEARCH
  • 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 128605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:39:44+00:00 2026-05-11T05:39:44+00:00

Just a simple program to get used to pointers. The program is supposed to

  • 0

Just a simple program to get used to pointers. The program is supposed to put the contents of a portion of my memory into a character array in reverse order of how the memory is read. I.E. looking at descending memory address, and I want to store it in descending order in a character array.

My compiler keeps telling me: ‘error incompatible types in assignment’

On the line with the realloc function

What am I doing wrong? I seems to me that both ‘reverse’, and the result of realloc should be pointers to type char?

My code:

int main(){ char  first[]='hello mark', strng='h', reverse[]=''; char* ptr=&first[10]; int i=0;     while(ptr > (&strng-0xf4240)){         printf('%c', *ptr--);         reverse = realloc(reverse, (i++ * sizeof(char)));         reverse[strlen(reverse)-i] = *ptr;     } printf('%s', reverse); return 0; } 

Thank you!

EDIT: Sorry I mis-posted these as comments below

Thanks for the help, the first and second comment got it! I did have the required #includes, I just forgot to copy them into stack overflow. You were right, now I’m stuck on the non-null terminated strlen(). I’ll solve that one on my own. Thanks again!

I spoke too soon, it compiled alright, but there is a logic error. The while loop will execute one time. However, subsequent loops still fail, regardless of the initial value of i. The line that causes the failure is the the line that calls realloc

  • 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. 2026-05-11T05:39:44+00:00Added an answer on May 11, 2026 at 5:39 am

    You can’t realloc memory that wasn’t malloced in the first place. You should declare reverse as ‘char *’ and malloc it to start with.

    This will get you going, but you really should think about reallocing in chunks, rather than one byte at a time. Oh, I didn’t bother to fix the fact that ‘reverse’ is probably not null terminated when you try the strlen – I’ll leave that as an exercise for the reader.

    int main(){ char  first[]='hello mark', strng='h'; char* reverse; char* ptr=&first[10]; reverse = (char*)malloc(1); reverse[0] = '\0'; int i=0;     while(ptr > (&strng-0xf4240)){         printf('%c', *ptr--);         reverse = (char*)realloc(reverse, (i++ * sizeof(char)));         reverse[strlen(reverse)-i] = *ptr;     } printf('%s', reverse); return 0; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 97k
  • Answers 97k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll need two main custom controls: the main view and… May 11, 2026 at 7:21 pm
  • Editorial Team
    Editorial Team added an answer First of all, singletons are usually a bad design and… May 11, 2026 at 7:21 pm
  • Editorial Team
    Editorial Team added an answer This is an approach I have used in the past:… May 11, 2026 at 7:21 pm

Related Questions

Given a string like this: <a href=http://blah.com/foo/blah>This is the foo link</a> ... and a
I'm trying to make a simple blackjack program. Sadly, I'm having problems right off
I need to implement a dynamic array by myself to use it in a
Aparently, encoding japanese emails is somewhat challenging, which I am slowly discovering myself. In

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.