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

  • Home
  • SEARCH
  • 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 8472367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:03:01+00:00 2026-06-10T17:03:01+00:00

I have written a code that reads from a file named network.dat The code

  • 0

I have written a code that reads from a file named network.dat

The code I wrote is

    f = fopen("network.dat", "r");
    if(f == NULL)
        exit(1);
    int read, N;

    printf("%p\n", f);//output file pointer, included this just to check if file is opened properly
    fscanf(f, "%d%d", &N, &read);//error here
    cout<<N; 

The file is being opened correctly and am getting the file pointer (49897488) as output but the line following it is where program stops working and I don’t get N as output.
Please tell if other detail is required.
Contents of network.dat are

10 1
1   6   1.28646
1   7   1.2585
2   9   1.33856

and so on. Am just focusing on first 2 numbers from the file i.e. 10 and 1.

  • 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-10T17:03:03+00:00Added an answer on June 10, 2026 at 5:03 pm

    As I stated in my comment, the problem is that your format specifier is incorrect. Try

    fscanf(f, "%d%d", &N, &read);
    

    Since you’re using cout I’m fathoming a guess that this is actually C++ code… honestly, you should really not be doing this the canonical C way. Instead, use ifstream.

    std::ifstream input("network.dat");
    int N, read;
    input >> N >> read;
    std::cout << N << ' ' << read << std::endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application written in Python 2.7 that reads user's file from the
I have a file download script that I have written, which reads files from
Hey everyone, I have written a script that downloads a zip file from a
I have written the following line of code that reads the data in a
I have a program written in Java that reads in a file that is
I have written code that opens 16 figures at once. Currently, they all open
I have written some code that loads an XML document using an XmlDocument object
I have written some code to ensure that items on an order are all
I have written code to perform a function that could take a while to
I have written a PHP function to take a video embed code that has

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.