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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:51:45+00:00 2026-06-17T14:51:45+00:00

im quite new to C, and im trying to populate a file wide array

  • 0

im quite new to C, and im trying to populate a file wide array variable with the results of a function, heres a simple code sample to show what i mean, can anyone point me in the direction of why this doesnt work?

#include <sys/types.h>
#include <dirent.h>
#include <regex.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>

static gchar *external_names;

void directories(int arraylength, gchar internal_names[][100]){
    int n;
    for (n = 0; n < arraylength; n++)
    {
        strcpy(external_names[n], internal_names[n]);
    }
    for (n = 0; n < arraylength; n++)
    {
        printf("%s internal with %s external\n",internal_names[n], external_names[n]);
    }
}

void main()
{
    gchar anotherarray[10][100];
    directories(10, anotherarray);
}

[EDIT] latest code

#include <sys/types.h>
#include <dirent.h>
#include <regex.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>

static gchar *external_names[100];

void directories(int arraylength, gchar internal_names[][100]){
    int n = 0;
    //gchar external_names[arraylength][100];
    for (n = 0; n < arraylength; n++)
    {
        printf("%s %i\n","before", n);
        strcpy(external_names[n], internal_names[n]);
        printf("%s %i\n","after", n);
    }
}

void main()
{
    int n;
    gchar anotherarray[10][100];
    for (n = 0; n < 10; n++)
    {
        strcpy(anotherarray[n],"test");
    }
    directories(10, anotherarray);
    for (n = 0; n < 10; n++)
    {
        printf("%s internal with %s external\n",anotherarray[n], external_names[n]);
    }
}
  • 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-17T14:51:46+00:00Added an answer on June 17, 2026 at 2:51 pm
    static gchar *external_names;  //one dimensional array.
    

    external_names is a one dimensional array and you are trying to assign it from a two dimensional array internal_names.

    strcpy(external_names[n], internal_names[n]);
    

    This is what happens when you increment the index.

    &internal_names[1] =  &internal_names[0] + size_t*100
    &external_names[1] =  &external_names[0] + size_t*1
    

    To solve this,

    static gchar (*external_names)[100];
    

    should work.

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

Sidebar

Related Questions

I'm quite new to smart pointers and was trying to refactor some existing code
I am quite new to Django and jquery stuff. I am trying to populate
Quite new to maven here so let me explain first what I am trying
I'm quite new to CMake and I'm trying to use it to build a
I'm quite new to JavaScript andI'm trying to do the following: I've two webpages
I'm quite new to Cocoa and I am trying to setup a table view
I'm quite new to C and I'm trying to implement a binary tree in
Im quite new to spring mvc. What I'm trying to achive is separating static
I'm quite new to C++ and I've ran across a problem. I'm trying to
I'm trying to develop a module for Drupal, I'm quite new. The following piece

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.