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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:50:41+00:00 2026-06-13T22:50:41+00:00

Trying to create a pointer to an array (string of characters) that the user

  • 0

Trying to create a pointer to an array (string of characters) that the user enters.

Here i define my pointer and array in my class:

private:

char userWord[200];     // input word
char * userWordPtr; // Pointer to the beginning of the input word

Here is the function that reads in the information:

void WordFont::inputWord()
{

    cout << "What word would you like to draw?\n"
         << "The useable characters are: A E I O U Y B C D L M N R S T\n" ;
    cout << "Please enter your word: ";
    cin.get(userWord, 200);
    cin.clear();
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    userWordPtr = &userWord;

}

The user enters a word and my code does something (long if-else ladder) based on the letters of the word. But in passing a * Ptr to the if-else ladder, I can’t get the if-else ladder to recognize the null (/0) character when I’m incrementing the position of the pointer. I also get an error using the ‘&’ to reference the address of the beginning of the char array. I can’t figure out why I’m getting that error, and why the if-else ladder below doesn’t exit til ‘i’ gets to whatever random location in memory has a ‘/0’ character. If I do something as simple as entering ‘AAA’, it will well past the 4th position where the ‘/0’ character is.

Here’s the loop:

void WordFont::buildOutputArray(char * Ptr)
{

    length = 0;
    bool switchLooper = true;
    int i = 0;

    do
    {
        if(*Ptr + i == 'a' || *Ptr + i == 'A')
            constructA();
        else if (*Ptr + i == 'e' || *Ptr + i == 'E')
            constructE();
        else if (*Ptr + i == 'i' || *Ptr + i == 'I')
            constructI();
        else if (*Ptr + i == 'o' || *Ptr + i == 'O')
            constructO();
        else if(*Ptr + i == 'u' || *Ptr + i == 'U')
            constructU();
        else if(*Ptr + i == 'b' || *Ptr + i == 'B')
            constructB();
        else if(*Ptr + i == 'c' || *Ptr + i == 'C')
            constructC();
        else if(*Ptr + i == 'd' || *Ptr + i == 'D')
            constructD();
        else if(*Ptr + i == 'l' || *Ptr + i == 'L')
            constructL();
        else if(*Ptr + i == 'm' || *Ptr + i == 'M')
            constructM();
        else if(*Ptr + i == 'n' || *Ptr + i == 'N')
            constructN();
        else if(*Ptr + i == 'r' || *Ptr + i == 'R')
            constructR();
        else if(*Ptr + i == 's' || *Ptr + i == 'S')
            constructS();
        else if(*Ptr + i == 't' || *Ptr + i == 'T')
            constructT();
        else if(*Ptr + i == '\0')
            switchLooper = false;
        i++;
    }while(switchLooper);


}

Its probably a easy newbie mistake, and I’m sure you’ll spend notice lots of other problems, but any help I greatly appreciate.

Thanks,
Tom

  • 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-13T22:50:41+00:00Added an answer on June 13, 2026 at 10:50 pm

    The user enters a word and my code does something (long if-else ladder) based on the letters of the word. But in passing a * Ptr to the if-else ladder, I can’t get the if-else ladder to recognize the null (/0) character when I’m incrementing the position of the pointer.

    Actually, what you are doing by using *Ptr + i is:

    • dereferencing your Ptr pointer (you are accessing the value at the address pointed by Ptr)
    • then you are adding i to the value contained at the address Ptr

    Serge gave you the answer, you have to use *(Ptr + i) to get the character at that address.

    Here, you are shifting the Ptr pointer of i “blocks”.

    I also get an error using the ‘&’ to reference the address of the beginning of the char array. I can’t figure out why I’m getting that error,

    An array of char (or whatever) is “like” a pointer (there are a bunch of differences but I let you the pleasure of discovering them ), so when you are using str[i] it’s quite the same thing than *(str + i).

    And why the if-else ladder below doesn’t exit til ‘i’ gets to whatever random location in memory has a ‘/0’ character. If I do something as simple as entering ‘AAA’, it will well past the 4th position where the ‘/0’ character is.

    You shouldn’t have this problem anymore.

    What if the user enters 200 characters?

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

Sidebar

Related Questions

I have a 3x3 array that I'm trying to create a pointer to and
I'm trying to create an array of structs and also a pointer to that
I am trying to create an array of size n (where n is user's
Im trying to create a php function that converts a string date to a
I'm trying to turn this C++ code/answer (class that creates map string <-> some_array_of_predefined_function_types
I'm trying to create an array of pointer references to a double array. For
Ok so I am trying create a login script, here I am using PHP5
Background: I'm trying to create a pure D language implementation of functionality that's roughly
Hi everyone trying to translate an older C program that uses array of structures
I'm trying to create a GetCurrentLevel method that takes a point value as an

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.