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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:23:11+00:00 2026-05-30T20:23:11+00:00

apologies if this is a basic question but I haven’t been able to figure

  • 0

apologies if this is a basic question but I haven’t been able to figure it out from other posts. I’m trying to read a bunch of images that are labelled "1.jpg" "2.jpg" "3.jpg" etc. I’d like to do so using a for loop. The file reader (I’m using SOIL here, as recommended in the OpenGL nehe tutorial I’m following), requires a const char* as the filename input.

char numbers[6] = "123456"; 

for (int i=0;i<6;i++)
{
   const char* filestring = new char[5];
   *filestring = numbers[i] + ".jpg";

   texture[i] = SOIL_load_OGL_texture(filestring, ...
   ...  // filestring should be const char* form
}

The errors are:

(1) error: initializer-string for array of chars is too long [-fpermissive]

but i don’t see what is wrong with char numbers[6] = "123456"?

error: assignment of read-only location ‘* filestring’

error: invalid conversion from ‘const char*’ to ‘char’ [-fpermissive]

I’m a bit baffled. Would be grateful for any advice!

Thanks.

  • 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-30T20:23:13+00:00Added an answer on May 30, 2026 at 8:23 pm

    Change this:

    char numbers[6] = "123456";
    

    To this:

    const char numbers[] = "123456";
    

    The size of the array is determined automatically by the compiler, so you don’t need to specify it explicitly. You are trying to set it too small anyway because it is actually 7 bytes wide because of the trailing null terminator.

    It’s not strictly necessary for it to be const, but it makes it clearer what your intention is if you do mark it as such.

    Also, this won’t work:

    *filestring = numbers[i] + ".jpg";
    

    You can’t concatenate C strings that way. Easiest thing to do would be this:

    string filestring = string(1, numbers[i]) + ".jpg";
    

    When you need to use it as a C string you can do this:

    SOIL_load_OGL_texture(filestring.c_str(), ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize if this question is too basic, but I just can't figure out
Apologies if this is a very basic question, but I am preparing to create
Apologies for this basic question, but I am noob stumped. The below code works
I'm not experienced in Javascript, so apologies if this is a basic question, but
This, I'm sure is a pretty basic question about JavaScript, so apologies in advance.
Apologies if this is too ignorant a question or has been asked before. A
Apologies if this question is a bit obscure, I've been banging my head against
Apologies if this is a dumb question. In previous ASP.NET projects, I've been using
Apologies if this is a slightly noob question, but looking to clarify my thoughts
This is extremely basic and I apologize for asking such a rookie question. But

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.