I dont want this

Im creating a sort of shell, for my cybercafe
This will restrict my clients from accessing unwanted materials
so im programming a similar bash to

  1. to meet my goals
  2. to learn new things.

im creating it in C,
please have a look at the attachement.

i wish to avoid having a blank space when Enter is pressed.
i want it to react as bash does.
is there any means to catch the enter key before changing line?

Could you paste the code that you are using for this?

C,

This is a sample code that I wrote on a HP-UX 11.11 system. This prints a prompt and takes input. It does not act on the input, except when it receives exit - it exits.

#include<stdio.h>

int main() {
        char argarray[80];
        while(1) {
                fprintf(stdout,"! ");
                fgets(argarray,80,stdin);
                argarray[strlen(argarray)-1]='\0';
                if(!strcmp(argarray,"exit")){
                        break;
                }
                /*fprintf(stdout,"%s was input.\n",argarray);*/
        }
        exit(0);
}

You can uncomment the fprintf in the end to echo what was input.

im REwriting it at the moment,
AT THIS STAGE:
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

struct stat s;

main() {

char c[100];
int desc,length_c;
char * _tmp =".myAI~";

desc = open( _tmp , O_CREAT | O_RDWR , 500 );
if ( desc < 0 ) {
perror("myAI ");
exit(0);
}

if (fork()==0) {
system("clear");
do {

printf\("myAI\\\\&gt;� "\); 
scanf\("%s",c\);
	
length_c=strlen\(c\);
lseek\(desc,0,sizeof\(char\)\);
write \(desc,c,length_c\);

/*
if \(strcmp\("machine",c\)==0\) \{
	   system\("echo $USER@\`hostname\`"\);
   system\("echo kernel : \`uname -r\`"\);
   system\("kde-config --version | grep KDE"\);
\}
else */if \(strcmp\("exit",c\)==0\) \{
   exit\(1\);
\}
else printf\("myAI: %s : command not found\\n",c\);

} while (c!=NULL);
exit(1);
}
wait(NULL);
}

THATS FOR SURE IT WONT WORK;
its only to give your an idea where i am

I think that this is where your problem lies. You can replace the scanf with the fgets that I am using in the code that I have posted in this thread.

Thanks it works.
at this stage im here :stuck_out_tongue:

#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

struct stat s;

main() {

 char c[100];
 int tmp_desc,length_c;
 char * _tmp = ".myAI~";
 char * _myAIrc = ".myAIrc";


 tmp_desc = open( _tmp , O_CREAT | O_RDWR , 500 );
 if ( tmp_desc < 0 ) {
    perror("myAI ");
    exit(0);
 }
 
 if (fork()==0) {
   system("clear");
   while(1) {
	
	fprintf(stdout,"!"); 
	fgets(c,100,stdin);
	c[strlen(c)-1]='\0';	
	length_c=strlen(c);
	lseek(tmp_desc,0,sizeof(char));
//	write (tmp_desc,c,length_c);
	
	/*
	if (strcmp("machine",c)==0) {
    	   system("echo $USER@`hostname`");
	   system("echo kernel : `uname -r`");
	   system("kde-config --version | grep KDE");
	}
	else */if(!strcmp(c,"exit")){
                        exit(0);
                }
	else printf("%s command not found\n",c);
	
   } while (c!=NULL);
	exit(1);
 }
 wait(NULL);
 
}

FWIW - there are restricted shells available.

It's fun to learn C I guess, except that http://freshmeat.net has 750+ unix shell projects. Because every CS major everywhere has to write one for a project. You can learn from what other folks did instead of completely re-inventing the wheel.