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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:40:22+00:00 2026-06-08T19:40:22+00:00

Section of my code where error is occuring: int disk::access (const char fname[]){ int

  • 0

Section of my code where error is occuring:

int disk::access (const char fname[]){

    int char_count=77;
    int actual_count=0; //just to pass the tests.
    char c;

    cout << "the file name is " << fname << ", and the mode is " << mode << endl;
    if(strcmp(mode, "w")==0){
        for (int i = 0; i < size; i++) {
            //cout << "sgm to be written is " << sgm[i];
            fp=fopen(fname, "w");
            fprintf(fp, "%s\n",sgm[i]);
         }
        fclose(fp);
    }       
    if(strcmp(mode,"a")==0){
        fp=fopen(fname, "a");
        fprintf(fp, "%s\n", sgm);
        fclose(fp);
    }

    fp=fopen(fname, "r");

    do{
        c=fgetc(fp);
        if(c!=' ' && c!='\n')
        actual_count++; 
     }while(c!=EOF);
    fclose(fp);


    return actual_count;        
}

my error:

disk.cpp: In member function ‘int disk::access(const char*)’:

disk.cpp:67: warning: cannot pass objects of non-POD type ‘class
segment’ through ‘…’; call will abort at runtime

EDIT line 67 is: fprintf(fp, “%s\n”,sgm[i]);

EDIT SGM:

the cpp code:

disk::disk(int num_of_segments, const char* temp_mode){

    size=num_of_segments;
    sgm = new segment[size];  //initializes num_of_segments in a disk

    count=0;        
    if(strcmp(mode, "w")!=0||strcmp(mode, "a")!=0){
        strcpy(mode, "w");
    }

}

disk::disk(){

    sgm = new segment[20]; //initialize 20 segments in a disk
    size=20;  //keeps track of how many are initialized
    count=0;  //keeps track of how many are added
    strcpy(mode, "w"); //initialize disk access mode to w


}

the header code:

class disk {
    private:
        int size, count; //to keep a track of number of segments 
        char mode [2]; //a for append and w for write 
        segment* sgm;
        FILE *fp;

    public:
        disk(int num_of_segments, const char *temp_mode);
        disk();
        ~disk();
        const char* get_mode( ) const;
        segment get_segment(int pos) const;
        int get_segment_count( ) const;
        const segment* get_all_segments( ) const;
        int access(const char fname[ ]);
        disk& operator+=(const segment &rhs);
        disk& operator=(const disk &dk);
};

I haven’t come across a warning like this before. I did some searching and from what I gathered POD is “plain old data that is a struct without constructors, destructors and virtual members functions.” -Greg Hewgill

So if I understood that correctly, my error is that I do have constructors or destructors and or virtual member functions because it is non-POD?

I think I’m just confusing myself, I’m not sure how to go about fixing this error or even pinpointing where the problem is occuring.

All suggestions are welcome and greatly appreciated,

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-06-08T19:40:23+00:00Added an answer on June 8, 2026 at 7:40 pm

    I’ll venture a guess and say “segment” is a struct or a class and you’re trying to print it as a “%s” string.

    you need to either implement a function that converts segment to string. or print individual native fields of the segment.

    e.g. if you defined segment like this

    struct segment { char name[10]; int index; }
    

    should be handled either as

    print("%s:%d\n", seg.name, seg.index);
    

    or as

    inline std::ostream& operator << (std::ostream& os, const struct segment& seg)
    {
    return os<<seg.name<<":"<<seg.index;
    }
    

    and your method call becomes:

    std::ostringstream os;
    os<<seg;
    std::string segStr = os.str();
    printf("%s\n", segStr.c_str());
    

    you can also hand code a toString() type function to get a string representation of a segment.

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

Sidebar

Related Questions

I am getting this error for every int in this section of code; if(choice==2)
I got stuck with a NaN error in this section of code: void Robot::updatePos(int
I'm getting a javascript error. It has to do with this section of code:
Trying to create code section within an If condition throws error: Unexpected section keyword
There comes error with the auto-generated code section: R.drawable. Please suggest solution for the
I am getting an invalid null pointer error from this section of code. I
Here is a section of code used by CKEditor on my website: CKEDITOR.config.IPS_BBCODE =
I have a section of code which should be executed by a maximum number
I have a section of code that can be summarised as follows; void MyFunc()
This is the code section from inno setup.My intention is to make two Checkbox

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.