How to clear input buffer in C?

The program will not work properly because at Line 1, when the user presses Enter, it will leave in the input buffer 2 character: Enter key (ASCII code 13) and \n (ASCII code 10). Therefore, at Line 2, it will read the \n and will not wait for the user to enter a character. The … Read more

getline() vs. fgets(): Control memory allocation

My question is: Isn’t that dangerous? What if by accident or malicious intent someone creates a 100GB file with no ‘\n’ byte in it – won’t that make my getline() call allocate an insane amount of memory? Yes, what you describe is a plausible risk. However, if the program requires loading an entire line into … Read more

Dereference void pointer

printf(“\nlVptr[60 ] is %d \n”, *(int*)lVptr); This will cast the void pointer to a pointer to an int and then dereference it correctly. If you want to treat it as an array (of one), you could do a slightly ugly ((int *)lVptr)[0]. Using [1] is out of bounds, and therefore not a good idea (as … Read more

ld.exe: cannot open output file … : Permission denied

I had exactly the same problem right after switching off some (in my opinion unneccessary) Windows services. It turned out that when I switched ON again the “Application Experience” everything resumed working fine. May be you simply have to turn on this service? To switch ON Application Experience: Click the Windows start buttonn. In the … Read more

What are “prototypes” in a C program?

The book’s I’m using to learn C explains something called “prototypes” which I couldn’t understand properly. In the book, the following sample code explains these “prototypes”. What does this mean here? What are the “prototypes”? Please explain in simple terms.