logoISU  

CS256 - Principles of Structured Design

Fall 2021

Displaying ./code/sternflCode/p5.c

#include<stdio.h>

//counting rises, when the new number is greater than the old number

int main() {
  int num;     //new number
  int prev;    //previous number
  int count=0;
  FILE  *f = fopen("small", "r");
  if (1!=fscanf(f, "%d", &prev)) {
     printf("no numbers in the file\n");
     return 0;
   }
  while ( 1==fscanf(f, "%d", &num)) {
    if (num>prev)
      count++;
    prev = num;
  }
  printf("%d\n", count);
}