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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:39:25+00:00 2026-06-10T16:39:25+00:00

Working in C, I’m filling an array with char* return values from a function

  • 0

Working in C, I’m filling an array with char* return values from a function

 char* files[4][12];
 int i = 0;
 for (;;)
    {
      char* file = get_value();
      strcpy(files[i],file);
      i++;
      if (i > 4 || external_condition)
      break;

     }

      // When I break out of
      // my for loop the following
      // code executes

      for (i = 0; i < 5; i++)
       {
        if (files[i] != NULL)
        manipulate(files[i]);
       }

My problem is that if I break out of the first for loop without assigning values to all elements of files, my comparison in the second for loop fails. If only files[0] and files[1] have content, the loop processes files[2],file[3] and files[4] anyway.

  • 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-10T16:39:27+00:00Added an answer on June 10, 2026 at 4:39 pm

    files is declared as an “array of arrays of pointers to char”. Or if you prefer, as a two-dimensional array of pointers to char.

    So files[i] is of type “array of pointers to char” but you use it as just a “pointer to char”. That is wrong.

    That said, it is not clear what you want to do… maybe just:

    char files[5][13];
    

    will make more sense. 13 because you likely need 13 char strings (8.3 are 8+3+1=12 plus 1 for the ending NUL), and you seem to use 5 of them. Then initialize them to zero:

    memset(files, 0, sizeof(files));
    

    And use the check:

    if (files[i][0])
    

    to check if a text is initialized.

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

Sidebar

Related Questions

Working on calling a C function from my asm project. I'm trying to push
Working with COM interop, I can call a managed function from within unmanaged code.
Working in iOS 5 I have read a list of file names from my
Working with an undisclosed API, I found a function that can set the number
Working on game where plates will be falling from top to bottom. Some plates
Working demo CLick $(document).ready(function(e) { $('span#pijlr, span#pijll').show(); $('#gallery').css('overflow','hidden'); $('span#pijlr').click(function(e) { if (!$('#gallcont').is(':animated')) { var
Working on writing a custom property Handler for our custom file type in windows
Working sample using one Table SELECT t.* FROM ( SELECT TITLE.name, (TITLE.value-TITLE.msp) AS Lower,
Working on a project where I need to add points to an array. Here
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.

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.