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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:04:24+00:00 2026-05-13T14:04:24+00:00

I’m trying to use an array to hold inputs for a survey that will

  • 0

I’m trying to use an array to hold inputs for a survey that will have equal positive values on each side, but have a pointer point to the center of the array so negative pointer values can be used to access the array.

For example, the array would hold values from 0 to 30, the pointer would point to 15, and the user would be prompted to enter values between -15 and 15 where the array at the user’s value would be incremented.

I’m ok if my logic isn’t completely correct yet, but the problem I am having right now is incrementing the value (which I’m not sure if I’m doing it right by ptr[userInput]++, and outputting those values with printf. I saw someone else’s post about passing the array to printf actually is passing a pointer to the array, and that person said to de-reference it twice with either **ptr or (*ptr)[0], but my compiler (Mac XCode) does not seem to like it.

Any thoughts? Here is my code. I commented where my questions were:

#define ENDPOINT 15
#define TERMINATE 999
#define TEST_FILE "TestFile6.txt"

void RecordOpinions(void)
{
    int record[2 * ENDPOINT + 1];
    int *ptr = &record[ENDPOINT + 1];
    int userInput;
    int loopCount = -ENDPOINT;

    printf("ptr:%d\n", *ptr);  // this was a test for me trying to figure out how to 
                               // print the value of the ptr.

    printf("Please enter your opinion of the new TV show, Modern Family from ");
    printf("-%d(worst) to 0 to +%d(best).  Entering %d ", ENDPOINT, ENDPOINT, TERMINATE);
    printf("will terminate and tabulate your results: \n");

    scanf("%d", &userInput);
    while (userInput != TERMINATE) {
        if (userInput > ENDPOINT || userInput < -ENDPOINT) {
            printf("Invalid entry.  Enter rating again: ");
        }
        else {
            printf("You entered: %d\n", userInput);

            ptr[userInput]++;      // not sure if this is the right way to increment 
                                   // the array at the user's input value.
        }
        scanf("%d", &userInput);
    }
    printf("Rating entry terminated.\n");
    printf("Ratings:.\n");
    for (; loopCount <= ENDPOINT; ) {
        printf("%d\n", ptr[loopCount++]);   // this part is where I also need help
                                                // in trying to print out the value of
                                                // the ptr, not the address.
    }
}
  • 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-05-13T14:04:24+00:00Added an answer on May 13, 2026 at 2:04 pm

    As far as the immediate issues you raised in your question are concerned, your code is perfectly fine. I.e. you are working with your “two-sided” array correctly (and no, you don’t need any additional dereferences when you printf the values in the array).

    The one problem I see is that you have forgotten to initialize (to assign initial values to) your record array, which means that the output will be garbage anyway, regardelss of how you work with it.

    Also, as Dave Hinton noted in the comments, if you want to use the -ENDPOINT to +ENDPOINT range from the ptr origin, you need to initialize your ptr with &record[ENDPOINT], not with &record[ENDPOINT + 1]. Otherwise, if user enters the ENDPOINT value as the index, you’ll end up with out-of-bounds access on the right end. (And the value of record[0] will always remain unused on the left end.)

    P.S. I’d make quite a few “stylistic” changes, but they are beside the point in this case.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

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.