Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming the fix mentioned by Abhijit, why transform the first into the second? Are you aware that the second behaves differently to the first, because of the addition of <code>sscanf</code>? If your intention was to shorten the first, the second seems quite bulky. Rather than adding <code>sscanf</code> to the situation, why not shorten the first by declaring a <code>struct employee *e = employee + employee_num;</code> and using that repetitively, instead of <code>employee[employee_num]</code>?</p> <p>One "best practise" regarding <code>fgets</code> is to check it's return value. What do you suppose <a href="http://pubs.opengroup.org/onlinepubs/007904975/functions/fgets.html" rel="nofollow"><code>fgets</code></a> might return, if it encounters <code>EOF</code>? What do you suppose <a href="http://pubs.opengroup.org/onlinepubs/007904975/functions/fgets.html" rel="nofollow"><code>fgets</code></a> would return if it's successful?</p> <p>One "best practise" regarding <code>scanf</code> is to check it's return value. In regards to the return value of <code>scanf</code>, I suggest reading <a href="http://pubs.opengroup.org/onlinepubs/007904975/functions/scanf.html" rel="nofollow">this <code>scanf</code> manual</a> carefully and answering the following questions:</p> <ol> <li><code>int x = scanf("%d", &amp;employee[employee_num].salary);</code> What do you suppose <code>x</code> will be if I enter <code>"fubar\n"</code> as input?</li> <li>Where do you suppose the <code>'f'</code> from <code>"fubar\n"</code> will go?</li> <li>If it's <code>ungetc</code>'d back onto <code>stdin</code>, what would your next employee's last name be?</li> <li><code>int x = scanf("%d", &amp;employee[employee_num].salary);</code> What do you suppose <code>x</code> will be if I run this code on Windows and press CTRL+Z to send <code>EOF</code> to <code>stdin</code>?</li> <li><code>int x = scanf("%d %d", &amp;y, &amp;z);</code> What would you expect <code>x</code> to be, presuming <code>scanf</code> successfully puts values into the two variables <code>y</code> and <code>z</code>?</li> </ol> <p>P.S. <code>EOF</code> can be sent through <code>stdin</code> in Windows by CTRL+Z, and in Linux and friends by CTRL+D, in addition to using pipes and redirection to redirect input from other programs and files.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload