title: C - Extra new line input while using scanf()
body: <p>I have the below 'C' code for a Console Win32 application using Visual Studio. It checks for arguments and directly calls a function or gets inputs using <code>scanf()</code> and then calls the function. The program works perfectly if I give command line arguments, but when I give inputs using <code>scanf()</code>, it probably adds an extra new line character which I want to avoid.</p>
  
  <p>I know it does this because when I give arguments, after showing 'Press ENTER to quit...', it waits for the ENTER input, but doesn't do so when using <code>scanf()</code>. This problem occurs if I use <code>scanf_s()</code> too.</p>
  
  <p>Appreciate your help on this.</p>
  
  <p>Regards,</p>
  
  <p>Shahid</p>
  
  <pre><code>    unsigned long int ipv;
      unsigned int yrs;
      float acr, acl, asp, irr, psp;
  
          if(argc&lt;=1) {
              //get inputs
              printf("Initial value of portfolio: "); scanf("%lu", &amp;ipv);
              printf("Average cash rate: "); scanf("%f", &amp;acr);
              printf("Average cost of living: "); scanf("%f", &amp;acl);
              printf("Average return for share portfolio: "); scanf("%f", &amp;asp);
              printf("Initial removal for living expenses: "); scanf("%f", &amp;irr);
              printf("Percentage of shares in initial portfolio: "); scanf("%f", &amp;psp);
              printf("Years for the analysis: "); scanf("%u", &amp;yrs);
  
              //simulate the investment with given inputs
              simulate(ipv, acr, acl, asp, irr, psp, yrs);
          } else {
              if (argc == 8) {
                  //invsim 1000000 0.05 0.036 0.12 0.08 0.5 20
  
                  //simulate the investment with given inputs
                  simulate(atol(argv[1]), (float)atof(argv[2]), (float)atof(argv[3]), (float)atof(argv[4]), (float)atof(argv[5]), (float)atof(argv[6]), atoi(argv[7]));
              } else {
                  printf("Please enter arguments as...\ninvsim.exe ipv acr acl asp irr psp yrs");
              }
          }
  
  printf("\n\nPress ENTER to quit...");
  getchar();
  </code></pre>