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??? future depends on you...-_-
Accepting data in the lists should only terminate only if the escape key is pressed

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


	if (first==NULL)
		first= (ENTRY *)malloc(sizeof(ENTRY));
		temp=(ENTRY *)malloc(sizeof(ENTRY));

Recommended Answers

All 3 Replies

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.


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, learning, and sharing knowledge.