Computing.Net > Forums > Programming > system() function in C

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

system() function in C

Reply to Message Icon

Name: tetsugin
Date: July 22, 2003 at 20:56:28 Pacific
OS: winxp sp1
CPU/Ram: duron 892mhz/386 pc133
Comment:

hi, im trying to write a program that would run a system command using the system() function. My problem occurs in that the system() function appearently only accepts literal strings, how would i pass a variable into it. For instance run system("nbtstat -A a.b.c.d") where a, b, c, and d would be variables running in nested for loops. I was thinking maybe there was a way to store an int inside a char or combine an int and char into a literal string? thanks for your time



Sponsored Link
Ads by Google

Response Number 1
Name: Don Arnett
Date: July 22, 2003 at 21:05:59 Pacific
Reply:

You are partially correct. system() will accept only a string, although it doesn't have to be a literal string.

To do what you want, you need to create a string containing the command and parameters that you need and pass that string to system().

Something like:

char command[100];


sprintf(command,"nbtstat -A %d.%d.%d.%d",a,b,c,d);

system(command);

sprintf works just like printf except that it writes it's string into the memory pointed to by the first parameter (in this case the array 'command')


0

Response Number 2
Name: tetsugin
Date: July 22, 2003 at 21:15:47 Pacific
Reply:

wow, thankyou so much, i really appreciate your help :)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: system() function in C

file handling function in 'C'. www.computing.net/answers/programming/file-handling-function-in-c/2119.html

System-pause - in c#? www.computing.net/answers/programming/systempause-in-c/10626.html

function in C www.computing.net/answers/programming/function-in-c/10023.html