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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:44:50+00:00 2026-05-22T17:44:50+00:00

This program is really getting on my nerves: I am trying to read a

  • 0

This program is really getting on my nerves:

I am trying to read a line from a file with following information:

512 MB 136.186.99.1 00-25-B3-0B-31-29

which is in the format of double string string string

and the code I’m using is

fscanf(filePtr, "%lf %s %s %s", &Computer[i].ram, Computer[i].ram_unit, Computer[i].MACNo, Computer[i].IPV4);

but when I print Computer[i].ram_unit I get:

MB136.186.99.1

Please help me to find out what I’m doing wrong. Let me know if you like me to paste the entire code.

Thanks

  • 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-22T17:44:51+00:00Added an answer on May 22, 2026 at 5:44 pm

    First, you have MACNo and IPV4 reversed in your fscanf relative to the sample input.

    Can’t tell for sure without seeing the structure definition, but it looks like a possible array overrun. For example, if your Computer was defined like this:

    struct ComputerType {
        double ram;
        char ram_unit[2];  /* This needs to be 3 (assuming unit is always 2 chars long) */
        char IPV4[16];
        char MACNo[17];
    };
    

    when you read “MB” into ram_unit, you could end up having

    ram_unit[0] = 'M'
    ram_unit[1] = 'B'
    IPV4[0] = '\0'
    

    And then when you read in the IP address into IPV4 that makes it

    ram_unit[0] = 'M'
    ram_unit[1] = 'B'
    IPV4[0] = '1'
    IPV4[1] = '3'
    [etc]
    IPV4[10] = '1'
    IPV4[11] = '\0'
    

    When you go to print out ram_unit, the print function will start at the memory location &ram_unit[0] and keep on printing until it sees a NULL. But since the NULL ended up in IPV4[0] and that got overwritten when you read in the IP address, it won’t stop printing until it gets to the NULL at IPV4[11] and so you get the unexpected concatenation.

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

Sidebar

Related Questions

There's this program, pdftotext, that can convert a pdf file to a text file.
I just started matlab and need to finish this program really fast, so I
I'm getting really fustrated with this... With this simple xml: <?xml version='1.0'?> <root> <data>hello</data>
I am really getting confused on how pointers work. I am trying to write
I really need help on getting a simple GTK program in c++ running using
I'm not sure how to really word this. I've been getting into PHP CLI
For some reason, when I execute this program with the following expression 12 12
I have this program in c++: #include <iostream> using namespace std; int main() {
I just translated this program, #include <stdio.h> int dam[1000][1000]; int main (int argc, const
Can someone please explain why this program outputs 0x00000004? class AndAssignment { static void

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.