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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:52:28+00:00 2026-05-17T16:52:28+00:00

I have a program that contains the following piece of code for constructing an

  • 0

I have a program that contains the following piece of code for constructing an array of asterisks:

char array[Length][Height];

for (int count1 = 1; count1 <= Length; count1++)
{
    for (int count2 = 1; count2 <= Height; count2++)
    {
        strcpy(array[count2][count3], "*");
        cout << array[count2][count3];
    }
}
cout << endl;

When I attempt to compile the program, I receive the following output:

waves.cpp:48: error: invalid conversion from ‘char’ to ‘char*’
waves.cpp:48: error: initializing argument 1 of ‘char* strcpy(char*, const char*)’

The ‘char*’ part of the output lead me to do some reading on pointers, and while I understand the basic principle of them, actually implementing them is proving somewhat difficult (and I guess that’s the difference between reading about something and doing it).

If someone could tell me where I’m going wrong in this code so I could use it as a worked example, it would go a long way to helping me understand the use of pointers.

  • 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-17T16:52:28+00:00Added an answer on May 17, 2026 at 4:52 pm

    Try this:

    char array[Length][Height];
    
    for (int count1 = 0; count1 < Length; count1++)
    {
        for (int count2 = 0; count2 < Height; count2++)
        {
            array[count1][count2] = '*';
            cout << array[count1][count2];
        }
    }
    cout << endl;
    

    Note that your code contained off-by-one errors: count1 and count2 would go from 1 to Length/Height, which would skip the first byte in the array and write one byte past its size. In C/C++, array indices start at zero and end at length – 1. I corrected the errors in the code above.

    strcpy() is intended for copying strings from one place in memory to another. What you want to do is not to copy a string, but to assign a single char value (which, conceptually, is no different from an int apart from its size*). The C language has no native string type — instead, it uses continuous blocks of memory that end with a byte that has the value zero (null-terminator). Working with strings in this manner is difficult, painful and error-prone. Since your post is tagged with “c++”, I would advise you to use the C++ Standard Library’s string type when dealing with strings in the future.

    * On some platforms, an int might be no larger than a char.

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

Sidebar

Related Questions

Lets say I have an array numbers that contains the following values: int numbers
Good morning SO, I have a class that contains the following static array: public
I have to write a program that read from a file that contains the
I have a program that spits out both standard error and standard out, and
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that spits out an Excel workbook in Excel 2003 XML
I have a program that monitors debug messages and I have tried using a
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that runs osql.exe from microsoft sql server tools directory and

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.