I have a main program that implements some functions for a stack in C. While accepting input from the user I find unusual results. Can someone point out what is a better way to accept user input in C.  int main() {     int choice;     int flag=1;     char n;     char string[100];     while(flag==1)     {         printf("\nMake a selection\n");         printf("Enter 1 to push an element in the stack\n");         printf("Enter 2 to pop an element from the stack\n");         printf("Enter 3 to print the stack elements\n");         printf("Enter 4 to display the top element of the stack\n");         printf("Enter 5 to reverse a string using stack\n");         printf("Enter 6 to verify balanced brackets in an expression\n");         printf("Enter 9 to quit\n");         scanf("%d",&amp;choice);         printf("Entered choice %d\n",choice);         switch(choice)         {             case 1:                 printf("Enter an element to push into the stack --&gt;  ");                 scanf("%c",&amp;n);                 Push(n);                 break;              case 2:                 top=Pop();                 break;              case 3:                 PrintElements();                 break;              case 4:                 if(top==NULL)                     printf("Stack is empty");                 else                     printf("\nThe top element on the stack is --&gt; %c",top-&gt;data);                 break;              case 5:                 printf("Enter a string\n");                 fgets (string,100,stdin);                 printf("\n Original string is --&gt; %s",string);                 for(int i=0;i&lt;100;i++)                 {                     if(string[i]=='\0')                         string[i-1]='\0';                 }                 StringReverse(string);                 printf("Modified string is --&gt; %s",string);                 break;              case 6:                 printf("Enter a string\n");                 fgets (string,100,stdin);                 for(int i=0;i&lt;100;i++)                 {                     if(string[i]=='\0')                         string[i-1]='\0';                 }                 CheckParanthese(string);                 break;              case 9:                 flag=0;                 break;              default:                 printf("Incorrect selection");                 break;         }       }     return 0; }   Sample Output Here when I enter 1 it automatically skips the next scanf statement which asks for user input for an element to push into stack  Make a selection Enter 1 to push an element in the stack Enter 2 to pop an element from the stack Enter 3 to print the stack elements Enter 4 to display the top element of the stack Enter 5 to reverse a string using stack Enter 6 to verify balanced brackets in an expression Enter 9 to quit 1 Entered choice 1 Enter an element to push into the stack --&gt; Make a selection Enter 1 to push an element in the stack Enter 2 to pop an element from the stack Enter 3 to print the stack elements Enter 4 to display the top element of the stack Enter 5 to reverse a string using stack Enter 6 to verify balanced brackets in an expression Enter 9 to quit
I've been having a lot of problems trying to figure out how to use scanf().  It seems to work fine with integers, being fairly straight forward scanf("%d", &amp;i).  Where I am running into issues is using scanf() in loops trying to read input.  For example:  do {   printf("counter: %d: ", counter);   scanf("%c %c%d", &amp;command, &amp;prefix, &amp;input); } while (command != 'q');    When I enter in a validly structured input like c P101, it seems to loop again before prompting me.  This seems to happen even with a single:  scanf("%c", &amp;c)    in a while loop.  It'll do the loop twice before prompting me again.  What is making it loop twice, and how do I stop it? When I enter in less amount of input that programmatically wouldn't have another character or number such as q, pressing enter seems to prompt me to enter more.  How do I get scanf() to process both single and double character entries?
Plotting a Continuous signal If $R_{1}$ and $R_{2}$ are relations on a set S with $R_{1};R_{2}=R_{2};R_{1}$. Then $R_{1}$ and $R_{2}$ are bijective maps For the surjectivity part, I showed that if $(a,b)\in I$ then $(a,c)\in R_{1}$ and $(c,b)\in R_{1}$ and $(a,c)\in R_{2}$ and $(c,b)\in R_{2}$ for some $c\in S$. Now for arbituary $(x,y)\in R_{1}$ we have $(x,z)\in I$ which implies that $(y,z)\in R_{2}$. But also $(y,z)\in R_{1}$, so $R_{1}$ is surjective. Similar argument for $R_{2}$  And for Injectivity, I've tried to show that if $aR_{1};R_{2}c$ and $bR_{2};R_{1}c$, then $a=b$ but I am not entirely sure what $a=b$ means in this context. Do I have to show that there is an equivalence relation containing (a,b)?  edit: $R_{1};R_{2}$ is a composition of two relations and $I=R_{1};R_{2}$ What does `exec {STDIN}>&0` do? can my transit visa take me through munich and frankfurt? Rule of thumb for number of bootstrap samples Retrieving minimum width that contains specified fraction of all values I'd like to find the min/max boundaries of a sliding window of minimum size that contains a certain fraction of the total number of elements in an array or collection of numbers.   Example: taking integers to make it easier to explain, say the proportion of elements that we're looking for is 50% on this array:  [1,1,2,3,3,3,3,3,3,4,5,6,7,8,9,10]  The mystery function would return something like ( 2, 4 ), meaning that the minimum value is 2 and the max value is 4 (let's assume it's inclusive and note that these are VALUES, not indices). That little window contains 8 of the 16 values and it's only 2 units wide, the narrowest such window that contains half the number of values.  Note: the quartiles are [1,1,2,3], [3,3,3,3], [3,4,5,6], [7,8,9,10] so they are NOT what I'm looking for.  I can code it...may take some time to get it nice. Hopefully somebody has run across it before. Does it have a name?  Is there an existing method that somebody knows about?  I am interested in Python implementations.   UPDATE:  Thanks to Glen_b who gave the names 'short-half' and 'shortest interval' I was able to come up with this: DBCC ShrinkDatabase() DBCC ShrinkFile()    Do I need to run both DBCC commands in order to shrink the database? What is the difference between these two above? We are in the early stages of development of the official Stack Exchange Android app and we need your help with testing. To set a few expectations: there will be bugs, crashes, and missing features, all of which will be fixed in .    We are initially targeting Android devices running  (Android 4.1 or higher) starting with phones (up to ~5 inch) and eventually moving our way to tablets.    To register for alpha testing .  After you register we will send you an invite to a private Google community where you can find a link to download our app directly from the  store. The invitations will be sent out in waves, so if you don’t get an invite immediately, be patient.  Crash reports will be automatically reported back to us using . Bugs or feature requests should be reported here on meta and tagged . Please do not use the Google community to report bugs.  As always, we welcome your feedback and are committed to building the best mobile app possible for browsing the Stack Exchange sites. How can I fix a mistake I made on my income tax filing? [US] How can I fix a mistake I made on my income tax filing? jQuery get all divs which do not have class attribute Trouble downloading packages list due to a "Hash sum mismatch" error Is there a simple way to explain how Kepler's third law follows from the inverse square law that of gravity  (and laws of motion)  For example for Kepler's second law we can say it's because Gravity is a central force  What is it about the law of gravity which ultimately gives rise to Kepler's third law? What is the correspondence between the conserved canonical energy-momentum tensor, which is $$ T^{\mu\nu}_{can} := \sum_{i=1}^N\frac{\delta\mathcal{L}_{Matter}}{\delta(\partial_\mu f_i)}\partial^\nu f_i - \eta^{\mu\nu}\mathcal{L}$$ (the four conserved Noether currents corresponding to four possible spacetime translations)  where $\{f_i\}_{i=1}^N$ are the $N$ matter fields in the theory, and we assume $f_i\mapsto\alpha^\nu\partial_\nu f_i$ for translations,  and stress-energy tensor from the Einstein-Hilbert action, which is: $$ T_{\mu\nu}\equiv-\frac{2}{\sqrt{-g}}\frac{\delta\mathcal{L}_{Matter}}{\delta g^{\mu\nu}} $$   In particular, how do you get that the two are equal (are they?) for Minkowski space, for which there is no variation in the metric? How do I scale the enormously sized desktop icons on Ubuntu 18.04? A conjectured closed form of $\int\limits_0^\infty\frac{x-1}{\sqrt{2^x-1}\ \ln\left(2^x-1\right)}dx$ Cannot create custom config entity fails because ID is blank Moment of inertia of a cylinder about its base I've tried to find the moment of inertia of a cylinder rotating about an axis parallel to its base (i.e about the 'End diameter') as one can see  . But when I checked my results with different references ,I've found that it's incorrect!.I need a help to figure out where I did it wrong. since $$I=\int\limits x^2.dm$$ $$dm = \rho.dv$$ where $$dv= r.d\theta . dr .dh$$ &amp; $$\rho=\frac{M}{\pi R^2 H}$$ $M$:cylinder total mass. $H$:total height of cylinder. $R$:the radius of the cylinder. The distance of each infinitesimal element from the axis of rotation would be : $$\sqrt{r^2+h^2}$$ Therfore, $$I= \frac{2M}{ R^2 H}\int\limits_{0}^{R} \int\limits_{0}^{H}\, r(r^2+h^2)dh\,dr$$ and this gives a result of : $$\frac{M~H^2}{3}+\frac{M~R^2}{2}$$ Which is obviously wrong since the second term should be multiplied by a factor of $1/2$. How do I set a background image while I am editing? Fix terminal after displaying a binary file Export/Deploy Drupal site/page to static? (no cache) I wonder if there is an existing  module that can help in the subject. I am not looking for a caching module (like Boost or Varnish), but a way to export my whole site (or only certain pages) into static.  The idea is that I want my web server will be a very simple and light and will only serve static files (html/css/js) - no database on production, no php engine will be installed on server. All the Drupal engine will be on another server, export will be done each time adding/editing/changing a node or view, and a new set of html files will be created in a directory structure.  These files will later on be copied to the production site that will serve always and only static files, no .htaccess that will check requests if file exist etc.   Is there a module for that, or a workaround that this can be achieved with Drupal?  Thanks