How do I make this code work in c++ Like it works in Batch. For some reason it wont use %ipcode%. So I cant input ip's to see if there online.
In c++ its like this -
system("set /p %ipcode%= ip=\"");
-
-
system("ping %ipcode%\"");
In batch its like this -
set /p ipcode= ip="
-
-
ping %ipcode%"
13 1430
How do I make this code work in c++ Like it works in Batch. For some reason it wont use %ipcode%. So I cant input ip's to see if there online.
In c++ its like this -
system("set /p %ipcode%= ip=\"");
-
-
system("ping %ipcode%\"");
In batch its like this -
set /p ipcode= ip="
-
-
ping %ipcode%"
The issue that you are running into is because C/C++ handles strings differently. What I would recommend is creating a string to hold the first part of the command up to the variable. Then make sure the variable is of the same type, and combine the two strings (or char arrays, or whatever you decided to use), and then add whatever else you need after it. Then you can pass the system command a variable, which will be interpreted as a string of the entire command (with proper IP address).
I'm not sure how much you know about strings, so I'll give you a basic strings intro at the bottom of the page.
The trouble here is that the two calls to system() each set up a separate, independent run of cmd.exe. So, the second call cannot "see" the value of the %ipcode% variable you prompted for and set during the first call.
I would suggest using C code to prompt for the ipcode, then format the answer into the second command and so call system() just once.
The trouble here is that the two calls to system() each set up a separate, independent run of cmd.exe. So, the second call cannot "see" the value of the %ipcode% variable you prompted for and set during the first call.
I would suggest using C code to prompt for the ipcode, then format the answer into the second command and so call system() just once.
Ooooh, good call. I totally missed what was going on in the first call...
Nice catch, ravenspoint.
Do you know what kind of code should be replaced with system()?
Do you know what kind of code should be replaced with system()?
I do not understand the question.
The trouble here is that the two calls to system() each set up a separate, independent run of cmd.exe. So, the second call cannot "see" the value of the %ipcode% variable you prompted for and set during the first call.
I would suggest using C code to prompt for the ipcode, then format the answer into the second command and so call system() just once.
How would I go on doing this in a c code?
How would I go on doing this in a c code?
Do you know how to prompt the user to enter a value into a C program?
Do you know how to use sprintf()
I am sorta new to c++. For right now I know batch code's so I was using system(). I am not to sure of sprintf()
I just need a quick deminstration how it work's with %ipcode%.
I am sorta new to c++. For right now I know batch code's so I was using system(). I am not to sure of sprintf()
I just need a quick deminstration how it work's with %ipcode%.
OK. Let's take it step by step.
Write a small program to prompt the user, receive what the user types in, and then print it out again.
If you cannot make it work, post your code here. I, or someone will help you sort it out.
If it works, great, you are about 80% done and we can finish it off.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("set /p ipcode= ip=\"");
system("ping %ipcode%\"");
return EXIT_SUCCESS;
}
This is what im talking about by not finding %ipcode%.
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
system("set /p ipcode= ip=\"");
system("ping %ipcode%\"");
return EXIT_SUCCESS;
}
This is what im talking about by not finding %ipcode%.
I believe I answered this question, in my first post. The two calls to system are entirely independant from one another. The value the user sets ipcode with is lost when the second system call is made.
Why are you repeating your initial question?
Here is the psuedo code of the program you need to write:
- prompt user, using printf()
- receive ip from user, using scanf()
- format system command, using sprintf()
- call system()
Oh I was just showing you the code. Because the last one wasnt right.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: PHPkemon |
last post by:
Hi there,
A few weeks ago I made a post and got an answer which seemed very logical.
Here's part of the post:
PHPkemon wrote:
> I think I've figured out how to do the main things like...
|
by: dave |
last post by:
I first started using HCW.exe to compile .rtf filew created with MS Word a
couple of weeks ago. I used the file | new
menu then selected New project in the dialog box and everything worked as...
|
by: Iain A. Mcleod |
last post by:
Hi
I'm stuck with the following schema validation problem in VS.NET 2003:
I have two types of xml document and related schema:
project and projectCollection.
A projectcollection is just a set...
|
by: CM |
last post by:
Hi there:
I have a web project which can be open and run without problem. I didn't
open the web application for a period and during which I didn't modified any
IIS items, but now I cannot open any...
|
by: CM |
last post by:
Hi there:
I have a web project which can be open and run without problem. I didn't
open the web application for a period and during which I didn't modified any
IIS items, but now I cannot open any...
|
by: alan_coffman2004 |
last post by:
Opening an ASP.NET VS2002 project in VS2003, am getting this error:
"Unable to open Web project 'MyProject'. The file
path 'c:\inetpub\wwwroot\MyProject' does not correspond to
the URL...
|
by: Tina |
last post by:
I have an asp project that has 144 aspx/ascx pages, most with large
code-behind files. Recently my dev box has been straining and taking long
times to reneder the pages in the dev environment. ...
|
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and...
|
by: Harry Simpson |
last post by:
I've been away from ASPNET - I open up a new Web app in VS2008 and go into
properties and select to use IIS instead of the personal web server. Then
I run in debug mode and it says I have to set...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |