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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:11:31+00:00 2026-05-31T00:11:31+00:00

Trying to write .ply parser to use .ply models in OpenGL. Trying to begin

  • 0

Trying to write .ply parser to use .ply models in OpenGL.

Trying to begin to read the .ply file and write all the lines of it out.
My program does this but when it print out the last line i get Unhandled exception:

Unhandled exception at 0x62aad540 (msvcr100d.dll) in PLY parser.exe: 0xC0000005: Access violation reading location 0x00000000.

This is my code:

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>


using namespace std;


int main ()
{
    char buffer[10000];
    FILE * myFile;
    myFile = fopen("walkman.ply", "r");
    if(myFile != NULL)
    {
        while (!feof(myFile))
        {

               cout<<fgets(buffer, 10000, myFile);

        }
        fclose(myFile);
    }
    else
    {
        cout<<"file not found"<<endl;
    }

    system("pause");
    return 0;
}

This may be foolish error in my code, but it would be great if someone can spot the error causing this.

  • 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-31T00:11:32+00:00Added an answer on May 31, 2026 at 12:11 am

    Before we get into what the bug is, you should know that the “Unhandled exception … Access violation reading location 0x00000000” message you get is not caused by a C++ exception; it’s the Windows equivalent of “Segmentation fault”. Your code tried to dereference the NULL pointer.

    Now, you have made one of the classic mistakes in working with FILE objects. feof(fp) does not become true when you reach the end of the file. It only becomes true after you have attempted to read past the end of the file at least once. Thus, your read loop will iterate until after fgets attempts to read past the end of the file. And when fgets attempts to read past the end of the file, it fails, and returns a NULL pointer, which you blindly passed to cout. Kaboom.

    (By the way, this is also how istream::eof() works.)

    The correct way to write this loop is

    while (fgets(buffer, 10000, myFile))
        cout << buffer;
    

    (Or, even better, one of these:

    while (fgets(buffer, 10000, myFile))
        fputs(buffer, stdout));
    
    while(myFile.get(buffer, 10000))
        cout << buffer;
    

    it being a little weird to mix stdio.h FILEs and iostreams as you are doing.)

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

Sidebar

Related Questions

Trying to write a python script to extract lines from a file. The file
Trying to write a couple of functions that will encrypt or decrypt a file
Im trying to write a single byte at a certain location in a file.
im trying to write an app that will display a list off lines from
Trying to write this small program to help me in my Stats class, everything
Trying to write a simple C# script to copy file to directory one level
Trying to write a byte[] to a file, which i think is working correctly
I'm trying write a C program that sends an UDP packet to a given
I' trying to write an xml file from Excel VBA using Microsoft XML 6.0.
I'm trying write a java program to send live microphone data over UDP, then

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.