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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:23:21+00:00 2026-05-28T20:23:21+00:00

This code is C/C++ and runs without warnings or debug messages. I’m using Code::blocks

  • 0

This code is C/C++ and runs without warnings or debug messages. I’m using Code::blocks with the GNU GCC compiler. This app worked perfectly once, then somewhere along the lines I messed up without noticing. Now every time it will allow a ip address input, but then freeze up and close. Why?

#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int ip[3];
char * inputIP;
int x;
string classValue;

void subnetClass()
{
if (x==0) classValue="Error: first octet may not be zero.";
if (x>0 && x<=126) classValue="Class A";
if (x==127) classValue="Loopback Address";
if (x>=128 && x<=191) classValue="Class B";
if (x>=192 && x<=223) classValue="Class C";
if (x>=224 && x<=239) classValue="Class D";
if (x>=240 && x<=255) classValue="Class E";
if (x>255) classValue="Error: an octet may not be more than 255.";

cout << classValue << endl;
}


int main()
{
cout << "Enter IP address in dotted-decimal form." << endl;
cin >> inputIP;
scanf(inputIP, "%d.%d.%d.%d" , &ip[0],&ip[1],&ip[2],&ip[3]);
int x=ip[0];
subnetClass();

return 0;
}

Build Log:

Checking for existence: C:…\IP subnetting app\bin\Debug\IP subnetting app.exe

Executing: “C:…\CodeBlocks/cb_console_runner.exe” “C:…\IP subnetting app\bin\Debug\IP subnetting app.exe” (in C:…\IP subnetting app.)

Process terminated with status -1073741510 (0 minutes, 27 seconds)

  • 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-28T20:23:22+00:00Added an answer on May 28, 2026 at 8:23 pm

    It might have worked with a little help from sheer luck even if you messed things up later, I believe. More or less everything is wrong. First you read the line into the area pointed to by uninitialized pointer (or maybe you read the pointer value, I’m not even sure what >> (char*) is supposed to do). You better change the definition to

    std::string inputIP;
    

    then you try to parse it used scanf and pass this pointer as a format string. What you meant is using sscanf. Assuming you changed the inputIP type, you can use

    sscanf(inputIP.c_str(),"%d....
    

    Then you assign to local main variable x that shadows global, which remains uninitialized when you use it in the function. Just remove the int part in the assignment like this:

    x=ip[0];
    

    and make the ip array of four elements.

    int ip[4];
    

    Then it may work. Unless I missed something else.

    And one more thing: if you use some source control (for instance using git you may start new project in no time) then you’d know what you’ve changed when you mess up, just commit early, commit often.

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

Sidebar

Related Questions

This code produces a FileNotFoundException, but ultimately runs without issue: void ReadXml() { XmlSerializer
This piece of code compiles and runs as expected on GCC 3.x and 4.x:
I have this code which runs without any errors but it isn't running the
this code compiles and runs without errors: class foo{ static foo *ref; foo(){} public:
This code runs on my local RoR/Windows 7 (64-bit): sql = ActiveRecord::Base.connection() last_pk =
I have a python script the runs this code: strpath = sudo svnadmin create
This code in a GUI application compiles and runs: procedure TForm1.Button1Click(Sender: TObject); begin Self
Please check this code out it compiles and runs absolutely fine.. The question is
I have some C++ source code with templates maybe like this - doxygen runs
Consider this code for loading, modifying and saving a Bitmap image: using (Bitmap bmp

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.