C++ :: Iterate Through Char Array And Pull IP Addresses To Test If They Respond
Apr 8, 2013
I am trying to write a loop that will iterate through a char array in C and pull the IP addresses and test them to see if they respond. My ultimate goal is to have the first one that responds returned in the function, but the loop is not running correctly. It will run through right the first time, but then will start over again.
Code output:
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: 2.2.2.2
result is "2.2.2.2"
result is "2.2.2.2"
Contents of srList b4 loop: 1.1.1.1
Server List: 1.1.1.1
result is "1.1.1.1"
Hitting else loop
Contents of srList in else: (null)
the question is; Write a program that prints out the memory addresses of each element in a two-dimensional array. Check to see if the values printed out make sense to you based on the way I explained it before.
Below is the code I have done. I am having problems printing the "-" sign to keep formatting with the board when the user enter in different dimensions other than [4][4].
Code:
#include <iostream> using namespace std; void printTable (int x, int y) { int **p_p_twoDimension = new int* [y]; for (int i = 0; i < y; i++) { p_p_twoDimension[i] = new int [x];}
So I have an issue with a homework assignment that I am coding. I am attempting to get a function to iterate through an array and search for a number that was stored in an array by the user. So far I can take the number, get the numbers displayed but in my menuChoice2 function, for some reason the program is not confirming whether or not the number is entered, and is only telling me that the number has not been found, instead of confirming that the number is in the array.
Here is my code thusfar:
#include <stdio.h> #include <stdlib.h> #include <stdbool.h> // Variables that are Globally declared int menuChoice = 0; int usernum[1000] = { ' ' };
[Code] .....
To be clear I am not getting any errors but something is telling me that the error is in the formatting of menuChoice2.
I was doing a side programming challenge in my workbook that asked me to dynamically allocate and array for test scores. So far I have an array that will accept an integer to allocate the amount of test scores and then will accept integers to populate the array, however when I try to cout the contents of the array the numbers are absurdly different than what was put in. Here's my code:
#include "stdafx.h" #include <iostream> using namespace std; void main() { cout << "How many test scores?" << endl; int scores(0);
[Code] ....
And this is the output screen: How many test scores? 4 Enter test score 1: 22 Enter test score 2: 33 Enter test score 3: 44 Enter test score 4: 55 -33686019 18472 55656634 201345063 Press any key to continue . . .
Why am I getting these crazy numbers? I've looked back and forth from examples in my book and it doesn't look like I'm doing anything wrong.
i'm using DataGridView and the sorting operation,by clicking the column header, is working fine , but when i add the drag and drop operation it doesn't respond . i think it can be fixed by disabling the drag and drop for the headers, but i just couldn't find a way to do that.
Now I would like to extract the data inside these comment tags and insert into excel sheet. Need to extract the comments in the xml tags shown in the able format? For example I want the value inside the <Autor> tag.
I'm trying to implement keyboard controls to move a sphere(Player) with respond to keypress. Currently, when I press any key my character will move to the right by 0.1. How can I move my character with w(up),a(left),s(down),d(right) in their respective directions using respond to keypress?
Code: class Player { private: double x, y; public: Player(double a, double b){x=a;y=b;} void respondtokeypress(char a)
I'm building a simple little program for minecraft to reduce the repetitiveness, I'm using getpixel, it's slow, but i only need to grab about 6-12 pixels.
but the problem is, I can get the pixel data if I capture from the entire desktop display, but as soon as I tell it to grab from the active window (wich goes MUCH faster) it doesn't return any colour value's.
I'd rather not have to use getDIBits or program in java or anything since I want to keep it fairly kiss, and if it can't be done, then.. ah well, I'll just grab from the entire desktop, speed isn't to much of an issue, but it'll be a pain to keep the window at the same place.
Code: #include <Windows.h> #include <iostream> using namespace std; // vvv Ignore this, it's just used for retrieving the handle of a window without giving the full window name vvvv struct results {
I have a problem in a c++ project. I have created a .dll file and hooked to an .exe
I want this .dll to make a ping or to send a message like hello somewhere, and IF ping or message doesn't receive an answer that's means the user has suspended-terminated this dll from the exe then the exe will close. How can i do that?
Using the array to accept 10 testscore. Calculate and print the highest, lowest, fifth test score entered and all the test score entered in reverse order.
How i would get it to print the highest,and lowest and in reverse order. I'm confused as to what to do...
I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.
this is the entire code:
#include <iostream> #include <fstream> #include <string> using namespace std;
[Code]....
at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.
I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.
/* this is my terminal readout joe bob <- nothing is put into (*playerPtr).name, why not? joe bob joe bob seg fault*/ /****************************************************************/ //This is here to show my struct/playerInit
I am looking for direction on what topic I should be reading up on. I am new to C++ and Windows MFC.
This is my real world problem, in the context of the application user. (these term do not refer to OPP concepts)
I want to create shapes (containers) in an application that will respond and collect other objects;
Imagine a Windows frame, containing several 2 dimensional squares. I want to be able to drag and drop marbles into the squares,and have the square retain and display the marbles in the square, in the order that they were dropped in.
How do I create the shapes, and how will the square sense when a marble is over it?
How would I create irregular shapes (a combination of lines and curves) that would be responsive to the marbles?
I was wondering if it is possible to check if two addresses, so pointers are equal.I was saving the address of an array, and later wanted to identify it by the address, so if my area has the address: int *my_array; // is equal to: 0x1e9aa3a2c ...Later when I go through a list of pointers like:
list= 0x1e9c7e060 0x1e9ba6640 0x1e9aa3a2c <== my address 0x1e9aa3a2c
I want the third one to be equal to my list, but with == it didn't work for me.
I want to take a starting IP on a local network, and loop through to an ending IP on a local network, pinging all the IP addresses in between. For instance, ping all IP addresses between 192.168.1.1 - 192.168.1.255 (user enters desired starting IP and ending IP in text boxes).
I have the ping functionality working, and i can make it all work with lots of messy string parsing.. but it seems sloppy to me.
I have to split the strings (start and end IP) to get the last octet, then subtract to get the range of IPs. Then loop through, adding 1 to the last octet, and converting back to a string each time.
The C# Ping class can use either a string or an IPaddress for its Send method. If I use IPAddress, I just have to convert it from the text box it originates in, but the adding 1 to the last octet in the loop is a hassle.
Anyway, I guess the only question I have is, if you had to loop through a range of IP addresses, how would YOU do it?
public Job(string ipStartIn, string ipEndIn) { long ip1 = Convert.ToInt64(ipStartIn); long ip2 = Convert.ToInt64(ipEndIn); IPStart = new IPAddress(ip1); IPEnd = new IPAddress (ip2); this.deviceAlive = false;
I'm taking a university course and one of our first projects dealing with C is to write a hash table (with chaining as a collision solution) that will hash loads of hexadecimal values into the table. I'm just brain storming right now but how practical is it to hash the values by converting them to decimal and working with that value in another function to organize the values? I'm thinking this might take a lot of time and memory because our code will be tested with text files that could have a few lines of hexadecimal addresses or millions of them.
"Write a program that compares the memory addresses of two different variables on the stack and prints out the order of the variables by numerical order of their addresses.
Does my solution look correct
Code: #include <iostream> using namespace std; int main() { int one = 1; int two = 2; if (&one < &two) cout << one << " " << &one << " " << two << &two << endl; else cout << two << " " << &two << " " << one << " " << &one << endl; }
My question is this: Is it possible to determine where functions are stored at compile time, so that at run time you can pass the memory address as a pointer to the interrupt handler so that it can directly call the function at memory location 'X'?
The newest project I'm working on would require to either somehow capture these addresses or to find a work-around so that instead of passing the pointer to the interrupt handler, the software would then need to be able to be non-interruptable.