Hi i have a syntax error on my c menu script that i cant figure out how to resolve
Error:
./menu.c: line 2: syntax error near unexpected token `('
'/menu.c: line 2: `void Menu(void);
Code:
#include <stdio.h>
void Menu(void);
void Top(void);
void Watch(void);
void ping(void);
void Muilt_ping(void);
int main(int argc, char** argv)
{
Menu();
return 0;
}
void Menu(void)
{
int choice;
do
{
printf("-------------------Menu--------------------\n");
printf("| 1. Run Top as child |\n");
printf("| 2. Run Watch as child |\n");
printf("| 3. Ping Google as child |\n");
printf("| 4. Ping both the Google and Bing |\n");
printf("| as child |\n");
printf("| 5. Exit |\n");
printf("-------------------------------------------\n\n");
scanf("%d",&choice);
switch(choice)
{
case 1: Top();
break;
case 2: Watch();
break;
case 3: ping();
break;
case 4: Muilt_ping();
break;
case 5: printf("Exiting program!\n");
exit(0);
break;
default: printf("Invalid choice!\n");
break;
}
} while (choice != 5);
}
void Top(void)
{
int ch;
int pid= fork() ;
if(pid!=0) {
wait();
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
printf( "Child process has finished. \n ");
}else {
printf ( " Child PID = %d , The PPID is %d \n",getpid(),getppid());
sleep(2);
execl ( "/usr/bin/top",".",(char*)0);
while ( (ch = getchar()) != '\n' && ch != EOF) ;
printf("\n\nPress ENTER to continue.");
while ( (ch = getchar()) != '\n' && ch != EOF)
;
return;
}
}
void Watch(void)
{
int ch;
int pid= fork() ;
if(pid!=0) {
wait();
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
printf( "Child process has finished. \n ");
}else {
printf ( " Child PID = %d , The PPID is %d \n",getpid(),getppid());
sleep(2);
execl ( "/usr/bin/watch",".",(char*)0);
while ((ch = getchar()) != '\n' && ch != EOF) ;
printf("\n\nPress ENTER to continue.");
while ((ch = getchar()) != '\n' && ch != EOF);
return;
}
}
void ping(void)
{
int ch;
int pid= fork() ;
if(pid!=0) {
wait();
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
printf( "Child process has finished. \n ");
}else {
printf ( " Child PID = %d , The PPID is %d \n",getpid(),getppid());
sleep(2);
execl( "/bin/ping", "ping", "-c 5", "www.google.com", (char*)NULL);
return;
}
}
void Muilt_ping(void)
{
int ch;
int pid= fork() ;
if(pid!=0) {
wait();
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
printf( "Child process has finished. \n ");
if(fork()) {
wait();
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
printf( "Child process has finished. \n ");
}else {
printf ( " Child PID = %d , The PPID is %d \n",getpid(),getppid());
sleep(2);
execl( "/bin/ping", "ping", "-c 5", "www.google.com", (char*)NULL);
}
}
else {
printf ( " Parent PID = %d, The PPID = %d, \n ",getpid(),getppid());
sleep(2);
execl( "/bin/ping", "ping", "-c 5", "www.bing.com", (char*)NULL);
}return;
}
What I have tried:
Somewhere told me i could remove the voids but this didn't work.
Menu();
Top();
Watch();
ping();
Muilt_ping();