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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:17:34+00:00 2026-06-14T06:17:34+00:00

Recently started working with pointers and have created a little script that is supposed

  • 0

Recently started working with pointers and have created a little script that is supposed to stich together some textfiles.

However when i try to call fputs i get a coredump/segmentation error. I suspect it is because of the way that the file pointer is saved. I find the files saves it in an array and tries to retrieve it later on.

the FILE pointer is saved in a struct. Does somebody instantly spot my fault? i would be very grateful!

The struct:

typedef struct{
int listSize;
int listCapacity;
FILE *fileStream;
}FileList;

Creating the struct

FileList fileList;
fileList.listSize=0;
fileList.listCapacity=1;
fileList.fileStream=calloc(fileList.listCapacity,sizeof(FILE));

and then i add the struct to the array by calling

void addFile(FileList* list, FILE* file)
{
    list->fileStream[list->listSize]=*file;
}

However when i call

char* buffer[10];
size_t result=0;

result = fread(buffer,1,10,&fileList.fileStream[ii+currentGroupOffset]);
    fputs(*buffer,outPutFile);

it crashes, i tried to watch the value ii+currentGroupOffset making sure it doesnt go out the array bounds

any help at all appriciated! 🙂

  • 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-14T06:17:35+00:00Added an answer on June 14, 2026 at 6:17 am

    You can’t allocate and copy around FILE structures yourself – it’s an opaque data type. So, instead of creating an array of FILE structures, create an array of FILE * pointers:

    typedef struct {
        int listSize;
        int listCapacity;
        FILE **fileStream;
    } FileList;
    
    FileList fileList;
    
    fileList.listSize = 0;
    fileList.listCapacity = 1;
    fileList.fileStream = calloc(fileList.listCapacity, sizeof fileList.fileStream[0]);
    

    then add a FILE * pointer to the array by copying the pointer value:

    void addFile(FileList *list, FILE *file)
    {
        list->fileStream[list->listSize] = file;
    }
    

    and use it like so:

    char buffer[10];
    size_t result = 0;
    
    result = fread(buffer, 1, 10, fileList.fileStream[ii+currentGroupOffset]);
    fwrite(buffer, 1, result, outPutFile);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently started working on a very large C++ project that, after completing
I have recently started working on some open source project which I found relevant
I have recently started working with Android. I don't have that much experience with
I have recently started working on a legacy application that has most of its
I recently started working with a client that had an index.html file with this
This is a very elementary I realize, I have recently started working with asp.net
I started working on CodeIgniter recently and I'm having some issues with the .htaccess
I've recently started working with multi-threaded Winform applications and have run up against a
i have recently started working on C# and i am very amateur at it
I've recently started working with RoR for some projects and I quite like the

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.