Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 11-05-2007, 12:08 AM   #1
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 ??

#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
		printf("Type in some commands for example 'pwd', 'ls', 'ps', 'quit'\n");

	do {
		/* display the prompt i.e.$ */

		/* 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);

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

	} 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");
	} else{ // error in fork() call
		printf("<err> error in executing the command\n");
Old 11-05-2007, 12:38 AM   #2
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).


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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:03 PM.

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