|
-
Jan 11th, 2001, 06:56 PM
#1
Thread Starter
Addicted Member
Hello,
I am pretty new to C programming and I would like to know how to do the following.
User types in Ip addy and Then pings ip. Here is my code now. I know all basic commands, but the system() isnt allowing two parameters. So thats where im lost.
Code:
#include <stdlib.h>
#include <stdio.h>
void main(void) {
float ip;
printf("Enter in ip addy: ");
scanf("%f",&ip);
system("ping %f", ip);
}
Any suggestions ?
Thanks
-
Jan 11th, 2001, 06:59 PM
#2
Frenzied Member
Are you sure an IP address can be expressed as a floating point number? I would have thought you would need a string for that.
Harry.
"From one thing, know ten thousand things."
-
Jan 11th, 2001, 07:03 PM
#3
Thread Starter
Addicted Member
Okay how about this.
But it still errors on the two parameters.
Code:
#include <stdlib.h>
#include <stdio.h>
void main(void) {
char ip[50];
printf("Enter in ip addy: ");
fgets(ip,sizeof(ip),stdin);
sscanf(ip, "%s", ip);
system("ping %f", ip);
}
-
Jan 11th, 2001, 07:23 PM
#4
Frenzied Member
I think you have the wrong idea of format strings - you can't use them in every function, only some. Use sprintf() to create the string first and then send it to system(), like this:
Code:
#include <stdlib.h>
#include <stdio.h>
void main(void)
{
char ip[50];
printf("Enter in ip addy: ");
fgets(ip,sizeof(ip),stdin);
sscanf(ip, "%s", ip);
sprintf(ip, "ping %s", ip);
system(ip);
}
Harry.
"From one thing, know ten thousand things."
-
Jan 11th, 2001, 07:35 PM
#5
Thread Starter
Addicted Member
See I learn something new every day.
I never knew about sprintf().

Although it does not error , when it runs it just returns "unknown host command".
But at least now im on the right track 
Thanks Harry
-
Jan 11th, 2001, 07:37 PM
#6
Frenzied Member
No problem
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|