August 19, 2012

Go to statement,Run a Dos command in c++

Go to statement in c++

 #include   
 // The main() function.  
 int main()  
 {  
 for (int dept = 1; dept < 10; dept++)  
 {  
 std::cout << "Department " << dept << std::endl;  
 int empl;  
 do  
 {  
  std::cout << "Enter Empl # " "(0 to quit, 99 for next dept) ";  
  std::cin >> empl;  
 if (empl == 0)  
 goto done;  
 if (empl != 99)  
 std::cout << "Dept: " << dept << ", " << "Empl: " << empl << std::endl;  
 } while (empl != 99);  
 }  
 done:  
 std::cout << "Entry complete" << std::endl;  
 return 0;  
 }  


Use of  system function to run a dos command 

 #include"stdlib.h"  
 #include"stdio.h"  
 void main()  
 {  
 char get_ip[50];  
 int x;  
 char command[50];  
 printf("enter the ip to be pinged : ");  
 gets(get_ip);  
 printf("%s",get_ip);  
 strcpy(command,"ping ");  
 strcat(command,get_ip);  
 x=system(command);  
 printf("%d",x);  
 }