is there any way to complete destroy a string so i can reuse it? IE: my CLI, i type, it saves everything into a string untill i hit enter, then it null terminates it, and then i try to rewrite over it, but i can't get back to the begninning of it? how would i do that?
*string[0] ?
thanks in advance
how to go to the beginning of a pointer?
Re:how to go to the beginning of a pointer?
Code: Select all
char buffer[4096];
char *pbuffer = buffer;
if you malloc() memory, save this pointer so you can free() it later.
Re:how to go to the beginning of a pointer?
char input[MAXBUFLEN]; //the users input, MAX
char *pointerinput = input; //pointer to input
those are the variables, and below is the code i use when the user hits ENTER
what'ca think?
char *pointerinput = input; //pointer to input
those are the variables, and below is the code i use when the user hits ENTER
*pointerinput++ = '\0'; //null terminate our pointer!
printf("\nUnknown Command %s ", input ); //give simple error for now!
y++;
int i = 0;
int length = 0;
length = strlen( pointerinput );
for( ; i<=length; i++ )
{
pointerinput = ' ';
}
gotoxy( 0, y ); //start cursor there!
what'ca think?
Re:how to go to the beginning of a pointer?
you can optimize it like this:
Code: Select all
int
getuserinput(char *buffer, ssize_t maxlen)
{
// read from keyboard
if(strlen(new_input) >= maxlen)
return -1;
// go on with the command. copy command.
memcpy((void *)buffer, (void *)new_input, strlen(new_input));
return 0;
}
cli(void)
{
char buffer[4096];
while(1)
{
memset((void *)buffer, 0, sizeof(buffer)); // zero entire buffer
getuserinput(buffer, sizeof(buffer)); // save the user input
}
}