#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include "functions.h"

//change lower case to upper case letters
//Change upper case to upper case
void change_case(FILE *in, FILE *out) {
   char c;
   while((c = getc(in))!=EOF){
         if (c >= 'a' && c<= 'z'){
            c = c - 'a' + 'A';
            putc(c,out);
         }
         else if(c >= 'A' && c <= 'Z'){
            c = c + 'a' - 'A';
            putc(c, out);
         }
         else{ 
            putc(c,out);
         }
   }
   rewind(in);
}
 

//count number of words (Look for " " chars)
void count_words(FILE *in, FILE *out){
   char c;
   int num_words = 1;
   while((c= getc(in)) != EOF){
      if(c == ' '){
         num_words++;
      }
   }
   fprintf(out, "The number of words in this text file is: %i ", num_words);
 //reverse function
   rewind(in);
}  

//look for number of sentences in documents (Look for "." chars)
void count_sentences(FILE *in, FILE *out){
   int num_sentences=0;
   char c;
   while((c= getc(in)) != EOF){
      if(c =='.'||c=='!'||c=='?'){
         num_sentences++;
      }
   }
   fprintf(out, "The number of sentences in this text file is: %i", num_sentences);
   //reversefunction
   rewind(in);
}  


//look for integers, store, sum, average use is digit file
//traverse through array, can't use getc because character, use unget(c), then call fscanf(in, "%d", __)
void get_int(FILE *in, FILE *out){
   double average=0;
   int sum=0;
   char c;
   int i;
   int num=0;
   while((c=getc(in)) != EOF){
      if(isdigit(c)==1){
         ungetc(c, in);
         fscanf(in, "%d", &i);
         sum+=i;
         num++;
      }
   }
   average = (double)sum/num;
   
   fprintf(out, "The sum of the numbers is %d", sum);
   fprintf(out, "The average of the numbers is %f", average);
//reverse function
   rewind(in);
}
   
         

