LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-05-2007, 12:08 AM   #1
thhuang
LQ Newbie
 
Registered: Nov 2007
Posts: 1

Rep: Reputation: 0
Exclamation Error Prompt - 'Execute_command was not declared in this scope. Please help!


Hi Everyone,

i'm currently doing my assignment which will be due in this thursday..
howerver, when i run the code, compiler prompt me the error as,

Task1.cpp: In function ‘int main()’:
Task1.cpp:44: error: ‘execute_command’ was not declared in this scope


i'm not sure what is the cause of this, can anyone help ??

Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>

#define MAX_INPUT_SIZE 100
#define MAX_ARG   50

//Tracker for display start up message
class assignment2{

int displayMsg=0;

};


int main()
{
	char line[MAX_INPUT_SIZE+1];
	int n, retcode=1;

// Add in instructions to prompt user what to do
	if(displayMsg==0){
		printf("Type in some commands for example 'pwd', 'ls', 'ps', 'quit'\n");
	}

	do {
		/* display the prompt i.e.$ */
	 	printf("MYUNIXXX>>>");

		/* obtain input from the standard input i.e. keyboard input*/
	 	fgets(line, MAX_INPUT_SIZE, stdin);
    	
		/* this is to get rid of the CR/LF */
		n = strlen(line);
		line[n-1]='\0';
		/*printf("%s",line);*/

		/* exit the loop if "quit" command is entered */
		retcode = strcmp(line, "quit");
		if (retcode ==0) {
			printf("Bye ... see you again\n");
		} else {
			execute_command(line);
		}

	} while (retcode !=0);
}

int execute_command(char *cmd)
{
	pid_t  pid;
	int i=0;

	/* create a copy of process */
	pid = fork();

	if (pid > 0){ // parent copy ... wait for child process to complete 
		//wait((int *) 0);
	} else if (pid == 0){ // child copy ... execute the command 
		/* execute the command here ... should never come back */

//If execlp return, it will display a invalid msg, user try again
		i = execlp(cmd, cmd, NULL);
		//i = system(cmd);
		if (i!=0)
			printf("You have enter an invalid command\n");
			displayMsg=1;
			exit(-1);
			main();
	} else{ // error in fork() call
		printf("<err> error in executing the command\n");
		return(-1);
	}
}
 
Old 11-05-2007, 12:38 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
It seems that the function execute_command is called in main, but is not declared (after the #includes and #defines).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
N/w card declared as not existing prabhatsoni Linux - Software 0 09-28-2007 12:20 AM
ltoa not declared in the scope lucky6969b Programming 3 12-23-2005 08:44 AM
scope of an object and global scope lucky6969b Programming 7 12-09-2005 09:09 PM
errno.h, but it IS declared...... privateprimate Linux - Software 3 09-08-2004 07:37 PM
Apache 2.0.35 declared stable jeremy Linux - General 4 04-10-2002 11:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration