Can anyone tell what is wrong in the below program.I want to ping an ip address which is entered by the user.

#include <iostream>
using namespace std;

int main()
{
char ip1[30];
cout<<"Enter the Ip Address";
cin>>ip1;
system("ping ip1");
return 0;
}

Recommended Answers

All 3 Replies

#include <iostream>
#include <string>
using namespace std;

int main()
{
    std::string ip1;
    cout<<"Enter the Ip Address";
    cin >> ip1
    ip1 = "ping " + ip1;
    system(ip1.c_str());
    return 0;
}

error C2146: syntax error : missing ';' before identifier 'ip1'

this is the error when i compile it.

error C2146: syntax error : missing ';' before identifier 'ip1'

this is the error when i compile it.

Included in learning how to write C++ code is learning how to troubleshoot extremely common and self-explanatory compiler errors. The compiler has told you exactly what's wrong and where, why not try to fix it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.