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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:08:12+00:00 2026-06-12T09:08:12+00:00

I have a function which I’ve used previously in another program called findVertexNumber. It

  • 0

I have a function which I’ve used previously in another program called findVertexNumber.

It will not work for me in my new program.

Perhaps I’ve been staring at code for too long to spot the error, but it seems identical in implementation to me when I compare the two programs.

Hopefully someone can spot my error….

#include <stdio.h>
#include <stdlib.h>

int findVertexNumber(FILE *fp);

int main(int argc, char *argv[])
{
        if(argc != 2)                                                           //insure 2 arguments given, one for a.out and one for the test file
        {
                printf("Requires 2 arguemnts. Be sure to include test file location\n");        //result if request fails
                return 0;
        }

        FILE *fp;                                                               //variable declartion
        int numberVertices = 0;
        int i, j;
        fp = fopen(argv[1], "r");                                               //open the file provided

        numberVertices = findVertexNumber(fp);                                  //find the number of vertices in the graph
        fclose(fp);

        printf("Max vertex number is: %d\n", numberVertices);
}

int findVertexNumber(FILE *fp)                                                  //function finds the largest number in the file, assumed to be number of
{                                                                               //vertices
        int max = 0;
        int e1, e2;


        while(fscanf(fp, "%d %d", &e1, &e2) != EOF)                                     //continue to end of file
        {

                if(e1 > max)                                                    //check if e1 is greater than max
                {
                        max = e1;                                               //if true, update max
                }
                if(e2 > max)                                                    //check if e2 is greater than max
                {
                        max = e2;                                               //if true update max
                }

        }
        fclose(fp);                                                             //close file
        return max;                                                             //return max number, number of vertices
}

The file its reading is a text file, maybe there’s something wrong in the format of it?

Here it is:

1 3
1 4
2 3
2 4
5 7
5 8
6 8
6 9

The error comes from the while statement as far as I can tell through comment debugging and is :

*** glibc detected *** ./a.out: double free or corruption (top): 0x0000000000ee3010 ***
  • 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-12T09:08:13+00:00Added an answer on June 12, 2026 at 9:08 am

    I saw fclose(fp) twice. One in main(), the other in findVertexNumber()

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

Sidebar

Related Questions

hi i have function which is called by tinker listbox so i cannot return
I have function which takes in an parameter of a class called Triple, and
I have a function which is called recursively and I want to know the
I have this function which is called about 1000 times from main(). When i
I have function bar which I need to call. I'm new to using callbacks,
I have a function which takes an argument that is used in where clause
I have Razor function which outputs some data and as result does not return
I have one template function which will take a pointer type and i have
I have function which checks the score and will(I haven't finished) increases level if
Can I´m asking for advice. I have function which should return javascript object function

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.