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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:55:15+00:00 2026-05-27T04:55:15+00:00

I’m having quite a bit of trouble with something that should be really simple.

  • 0

I’m having quite a bit of trouble with something that should be really simple. In my program I have a struct called “Run”:

typedef struct{
    char name[MAXNAMELENGTH], day[MAXDAYLENGTH];
    int distance, intDay;
    Date startDate;
    Time startTime;
    Time runTime;
} Run;

I parse data from a text file to this struct by using fgets() to parse a single line into an array called line[] and then call this function:

void parseTable(char line[NUMBEROFLINES], Run run, Run runs[NUMBEROFLINES], int *j){
    sscanf(line,"%s %s %s %d, %s %d:%d %d %d:%d:%d",run.name, run.day, run.startDate.month, &run.startDate.date, run.startDate.year,&run.startTime.hours, &run.startTime.minutes, &run.distance, &run.runTime.hours, &run.runTime.minutes, &run.runTime.seconds);
    runs[*j] = run;
    *j+=1;    
}

Now this function correctly assigns all the data to the struct run and stores that struct in the array runs[], but after this I wish to assign the struct a new value: intDay.
For that I call upon the following function:

void dayToInt(Run run, Run runs[NUMBEROFLINES], int *i, int *a, int *b){
    if (strcmp(run.day,"Mon") == 0)
        run.intDay = 1;
    else if (strcmp(run.day,"Tue") == 0)
        run.intDay = 2;
    else if (strcmp(run.day,"Wed") == 0)
        run.intDay = 3;
    else if (strcmp(run.day,"Thu") == 0)
        run.intDay = 4;
    else if (strcmp(run.day,"Fri") == 0)
        run.intDay = 5;
    else if (strcmp(run.day,"Sat") == 0)
        run.intDay = 6;
    else if (strcmp(run.day,"Sun") == 0)
        run.intDay = 7;
    runs[*i] = run;
    *i += 1;
}

But this doesn’t store the intDay value in my array runs[] and I really don’t see why it doesn’t. I’ve looked here and on other forums to see examples of how to do it but there must be something I keep missing, so if anyone can tell me what it is then it would be greatly appreciated 🙂

  • 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-27T04:55:15+00:00Added an answer on May 27, 2026 at 4:55 am

    The issue here is “Pass-by-Value”.

    When you call the function:
    void dayToInt(Run run, Run runs[NUMBEROFLINES], int *i, int *a, int *b){

    the first parameter, run, is actually copied into a local copy for the function. When you modify run.intDay, it only modifies the local copy.

    When you return from the function, all local modifications are lost, and the original structure, at the caller’s scope, remains unchanged.

    To fix the problem, change the function to “Pass-by-Reference”, meaning, pass a pointer to the struct you wish to change:

    void dayToInt(Run *prun, Run runs[NUMBEROFLINES], int *i, int *a, int *b){
        if (strcmp(prun->day,"Mon") == 0)
            prun->intDay = 1;
        else if (strcmp(prun->day,"Tue") == 0)
            prun->intDay = 2;
    [etc, etc]
    

    Edit On further inspection, it looks like the line:

    runs[*i] = run;
    

    should perform a copy of the structure, and preserve changes at the caller’s scope.
    So I’m not sure why the changes to run.intDay are being lost. Investigating further.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,

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.