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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:09:09+00:00 2026-05-27T19:09:09+00:00

This code fails when I try to debug it using VC2010: char frd[32]=word-list.txt; FILE

  • 0

This code fails when I try to debug it using VC2010:

char frd[32]="word-list.txt";

FILE *rd=fopen(frd,"r");
if(rd==NULL)
{
std::cout<<"Coudn't open file\t"<<frd;
exit(1);
}
char readLine[100]; 
while(fgets(readLine, 100, rd) != NULL)
{     
    readLine[strlen(readLine) - 1] = '\0'; 
    char *token = NULL; 
    token = strtok(readLine, " ,"); 
    insert(readLine);
} 

Debugging results in

————————— Microsoft Visual C++ Debug Library———–

Debug Assertion Failed!

Program: …\documents\visual studio 2010\Projects\bfa\Debug\bfa.exe
File: f:\dd\vctools\crt_bld\self_x86\crt\src\fgets.c Line: 57

Expression: ( str != NULL )

For information on how your program can cause an assertion failure,
see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

————————— Abort Retry Ignore

The errno I get is 2;

  • 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-27T19:09:10+00:00Added an answer on May 27, 2026 at 7:09 pm

    My guess is that the file is failing to open, and you’re still passing it to fgets. Your if(rd==NULL) doesn’t stop execution of the fgets if it’s null, it just prints out a message and continues with execution.

    Some very basic errorr handling:

    const char* frd = "word-list.txt";
    
    FILE *rd=fopen(frd,"r");
    if(rd==NULL) {
        std::cout<<"Coudn't open file"<<endl;
        return 1;
    }
    
    char readLine[100]; 
    while(fgets(readLine, 100, rd) != NULL)
    {     
        readLine[strlen(readLine) - 1] = '\0'; 
        char *token = NULL; 
        token = strtok(readLine, " ,"); 
        insert(readLine);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works when I try it from a .py file, but fails in
I'm doing the following: [self.parentViewController dismissModalViewControllerAnimated:YES] This code fails using the Simulator but works
Challenge: I have this code that fails to compile. Can you figure out what's
This code does not throw an error but the query fails, that is, the
The following code fails in 'Evaluate' with: This expression was expected to have type
When I add this code to my Android 2.1 Java app, it fails: db=SQLiteDatabase.openOrCreateDatabase(Locations,
This feels like the kind of code that only fails in-situ, but I will
Why does this code fail to display the category name Apples using the current
I try to execute this code in Silcerlight 4 contol hosted in webpart: clientCtx
I write my debug information to a file using a separate thread. During startup,

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.