Note that there are some explanatory texts on larger screens.

plurals
  1. PODetecting change in value read by scanf
    text
    copied!<p>For an assignment we are supposed to read in a list of dates and associated values (temperatures) from a text document. Values in each line are separated by commas.</p> <p>Example data:</p> <pre><code>dd,mm,yyyy,x,y,z,w 01,01,2011,1.1,5.2,6.5,7.5 02,01,2011,2.1,5.2,6.1,1.1 03,01,2011,4.5,2.5,6.1,2.1 ... 30,01,2011,4.1,6.1,6.1,2.1 01,02,2011,2.5,6.1,7.1,6.3 </code></pre> <p>So far I have implemented a loop to read each line:</p> <pre><code>while(scanf("%d,%d,%d,%f,%f,%f,%f", &amp;dd, &amp;mm, &amp;yyyy, &amp;x, &amp;y, &amp;z, &amp;w) == 7) { } </code></pre> <p>We're given the assumption that there are no errors in the document, and no duplicate dates. </p> <p>However, there may be missing entries (not each month have complete data; missing days).</p> <p>I am having trouble detecting if each month's data (mm) is a complete month or only a partial month.</p> <p>Eg: 31 days in March 2011. If I have 31 entries from March, I need to print 'Full month', otherwise if there are missing days I have to print 'Partial month'.</p> <p>So far I have been using <code>if(mm==1){}</code> statements to separate each month inside the <code>while(scanf(...))</code> loop and then incrementing them in separate variables, then comparing it with the amount of days in a complete month, but I don't know how to implement it so it detects that mm has changed from the previous line (new month) and perform a certain action (e.g.: calculations) </p> <p>Sorry if this is confusing!</p> <p>We have not been taught arrays yet, only operations, loops and functions.</p>
 

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