473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help With My Project %ipcode%

Maylea
13
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

Expand|Select|Wrap|Line Numbers
  1. system("set /p %ipcode%= ip=\"");
  2.  
  3. system("ping %ipcode%\"");

In batch its like this

Expand|Select|Wrap|Line Numbers
  1. set /p ipcode= ip="
  2.  
  3. ping %ipcode%"
Jul 19 '07 #1
13 1430
sicarie
4,677 Expert Mod 4TB
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

Expand|Select|Wrap|Line Numbers
  1. system("set /p %ipcode%= ip=\"");
  2.  
  3. system("ping %ipcode%\"");

In batch its like this

Expand|Select|Wrap|Line Numbers
  1. set /p ipcode= ip="
  2.  
  3. 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.
Jul 19 '07 #2
ravenspoint
111 100+
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.
Jul 19 '07 #3
sicarie
4,677 Expert Mod 4TB
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.
Jul 19 '07 #4
Maylea
13
Do you know what kind of code should be replaced with system()?
Jul 19 '07 #5
ravenspoint
111 100+
Do you know what kind of code should be replaced with system()?
I do not understand the question.
Jul 19 '07 #6
Maylea
13
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?
Jul 19 '07 #7
ravenspoint
111 100+
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()
Jul 19 '07 #8
Maylea
13
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%.
Jul 19 '07 #9
ravenspoint
111 100+
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.
Jul 19 '07 #10
Maylea
13
#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%.
Jul 19 '07 #11
ravenspoint
111 100+
#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?
Jul 19 '07 #12
ravenspoint
111 100+
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()
Jul 19 '07 #13
Maylea
13
Oh I was just showing you the code. Because the last one wasnt right.
Jul 19 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
1
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...
4
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...
0
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...
4
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...
3
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...
7
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. ...
16
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...
16
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...
0
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
0
BarryA
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...
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.