System() and the sprintf() commands help

February 10, 2010 at 12:22:48
Specs: Windows Vista
hi, i'm trying to make a simple program which lets the user ping a website here is the code
#include <stdio.h>
#include <stdlib.h>

int main()
{
char cmd[100];
char input1;
printf("enta tha site u wanna ping \n");
scanf("%s",&input1);
sprintf(cmd,"ping %s",input1);
printf("%s",cmd);
system(cmd);
return 0;
}
it compiles fine but crashes when attempting to print cmd

if anybody could help that would be spectacular


See More: System() and the sprintf() commands help

Report •


#1
February 10, 2010 at 14:31:31
You've only allocated one byte to input1.

char input1[MAX_PATH] = { 0 };
fgets(input1, sizeof input1, stdin);


Report •

#2
February 10, 2010 at 16:33:00
thank you :)

Report •
Related Solutions


Ask Question