I am experimenting with using system commands in C++, and I am trying to make a pinger. Below is my script:
#include <stdlib.h>
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
char ip;
char *cmd;
cout << "Input IP: ";
cin >> ip;
sprintf(cmd, "ping %s", ip);
system(cmd);
return 0;
}
The code compiles and runs fine until you enter the IP you want to ping, at which point it gives me this:
Input IP: 8.8.8.8
Segmentation fault (core dumped)
I suspect it has something to do with sprintf, but I'm not sure since I'm a beginner when it comes to coding in C++
How do I fix this error?