please help me with my problem...
i have here a running program...but then you have to press the keyboard twice in order to input data..
can you help me to modify my source code???please..my future depends on you...-_-
specification:
Accepting data in the lists should only terminate only if the escape key is pressed

Assumption:
new->is a string variable that accepts data
*next->is a defined pointer of the list
*temp,*first,*last->are pointer variables

procedure:

while(1)
{
z=getch();
if(z==27)
	break;
else
	{
	gets(new);
	if (first==NULL)
		{
		first= (ENTRY *)malloc(sizeof(ENTRY));
		strcpy(first->string,new);
		first->next=NULL;
		last=first;
		}
	else
		{
		temp=(ENTRY *)malloc(sizeof(ENTRY));
		strcpy(temp->string,new);
		temp->next=NULL;
		last->next=temp;
		last=temp;
		}
	}
}

click here to see the problems with gets()

>>but then you have to press the keyboard twice in order to input data..
You could write your own keyboard input function that replaces gets() and uses only getch() to get the keys. Of course if you do that then you will also have to handle the other special keys, such as backspace, left/right arrows, del, etc.

>my future depends on you...-_-
Then I wouldn't bet on your future. ;)

Let's see where do I start?
Ah, yes, use proper coding tags when you post some code in this forum. Example here.

gets(new);

Bad, bad function.
gets() is not an alternative. Learn how to use fgets().

new=(char *)malloc(13);

Every single time you use malloc to allocate memory you need to check that memory was set apart for it, successfully.

if (new == NULL) {
    /* memory error code here */
}

And when you are done with that piece of memory it needs to be release. free(new); void main() is a no, no. Click and look what happened to the last guy that wrote void main if you dare. main() inside a host operating system will always return an int, so a proper writing would be:

int main( void )
{
     return 0;
}

And since this is an ANSI C forum, I probably need to mention that #include<conio.h> , getch(); , and clrscr(); are not C Standards and therefore will only work with some compilers that support those functions and header file.
Go ahead. Make the changes and then, we can start talking about your future.

If you can't figure out how to get character input from the keyboard, YOU DAMN SURE SHOULDN'T BE USING MALLOC.

first learn basic programming first before starting a career in writing shitty code full of memory leaks, mmkay?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.