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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:47:16+00:00 2026-06-17T13:47:16+00:00

static void retrieveData(const char* filename) { FILE *f; char s[256]; int a[10]; int b[10];

  • 0
static void retrieveData(const char* filename)
{
    FILE *f;
    char s[256];
    int a[10];
    int b[10];
    char c[10][10];
    ...
    .....
    long j[10];

    sprintf(s, "some code %s", filename);
    if ((f = popen(s, "r")) != NULL) {
        while (fgets(s, sizeof(s), f)) {
            if (strncmp(s, "A........ {
                sscanf (s,"........
                a[0] = var1;
                b[0] = var2;
                c[0] = var3;
                ...
                .....
            }
            else if (strncmp(s, "B........ {
                sscanf (s,".........
                a[1] = var4;
                b[1] = var5;
                c[1] = var6;
                ...
                .....
            }
            else if .........more codes
        }
        pclose(f);
    }
}

I would like to get all data in arrays a,b,c….,j.

void getData(int argc, char **argv)
{
    int n;
    int a[10];
    int b[10];
    char c[10][10];
    ...
    .....
    long j[10];

    retrieveData("filename1");

    for (n = 0; n < 10; ++n) {
        printf("%d\n", a[n]);
    }

    for (n = 0; n < 10; ++n) {
        printf("%d\n", b[n]);
    }

    ...... more codes


    retrieveData("filename2");

    for (n = 0; n < 10; ++n) {
        printf("%d\n", a[n]);
    }

    for (n = 0; n < 10; ++n) {
        printf("%d\n", b[n]);
    }

    ...... more codes

}

filename1 and filename2 contain same data structure but difference values.
Please someone show me how…
I’m compiling under linux c.
sorry for my poor english.

  • 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-17T13:47:17+00:00Added an answer on June 17, 2026 at 1:47 pm

    You probably need to define them as global variables, and not local, then you can access them in any function.

    Put this at the top of the .cpp file that contains both functions.

    int a[10];
    int b[10];
    char c[10][10];
    

    And please use better names 🙂

    Alternatively, since in your case the one function calls the other, you can pass the arrays in as pointers as arguments to the function, but that will be painful in the case of the 2D pointers atleast.

    A third, syntactically simpler, option is to wrap the 3 arrays within a struct and pass a pointer to that struct around, thanks Basile Starynkevitch.

    typedef struct{
        int a[10];
        int b[10];
        char c[10][10];
    } Arrays;
    
    void getData(int argc, char **argv)
    {
        ...
        Arrays a;
        retrieveData("...",&a);
        ...
    }
    
    void retrieveData(const char* filename, Arrays *a){
        a->b[1] = 1;
        ....
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static void displayInfo(KeyEvent e){ int id = e.getID(); String keyString; char c =
public static void WriteLine(string text) { StreamWriter log; if (!File.Exists(Filename)) { log = new
static void HandlePackets(void* pParams) { int iResult = 0; char recvbuf[MAX_PACKET_LENGTH]; printf(Packet handling started\n);
static void testlock() { for(int i=0;i<10000000;i++) { float f=2.0/i; } } static void TEST()
static void Main() { string str; str = Console.ReadLine(); while (str != null)//HERE! {
static void Main(string[] args) { //read in the file StreamReader convert = new StreamReader(../../convert.txt);
public static void main(String[] args) { int i = 0; while(i==0){ System.out.println(Possibilities: R, T,
Code static void MyClass::ThreadEntryStatic() { //... } void MyClass::Begin() { CreateThread(..,ThreadEntryStatic,..); } In which
public static void fillCheckList(string ListType,int RecordNum,CheckBox chkRequired,TextBox txtComplete,TextBox txtMemo) { string sql_Check = String.Format(@SELECT
public static void Main (string[] args) { int k = 0; int i =

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.