We are writing in C and I cant get this homework done can an

We are writing in C and I can\'t get this homework done, can anyone offer assistance?

Ever wonder what is in a file? Ever wonder how many times each character actually occurs in the file? Probably not - most people never think of things like that. This program takes an input source and tells the user what characters that source contains. It does not worry about whitespace (spaces, tabs, newlines) but instead focuses on the printable characters. These include; 26 upper-case letters, A - Z and 26 lower-case letters, a - z and 10 digits, 0-9 32 special characters: ! This program reads from standard input until end-of-file. Once it hits end-of-fuel, it tells the user what characters it saw, ordered from the most-occurring character down to the characters that it did not see. As an example, if the user entered the input below (shown in red), the program generates the output shown in blue. Create a directory projects on your machine. In that directory, create a file named contents. c in contents. c, write the code needed to find out what characters exist in the input. Make sure that you: Have a header block of comments that includes your name and a brief overview of the program, o Read from standard input until you hit end-of-file o Prints the expected output in a clear, legible format to test your program with various inputs, you can redirect input so that it comes from a file instead of the keyboard. As an example, if you wanted to see what the contents of your contents. c file was, you would type the command./a. out

Solution

#include<stdio.h>
#include<ctype.h>

int charCount = 0;
int lwrcaseCount = 0;
int uprcaseCount = 0;
int digitCount = 0;
int specialCount = 0;
int count[94] = {0};
char charSym[94]; //94 = 126 - 33 +1

void initialze() {
   int i;
   for (i=0; i<94; i++)
       charSym[i] = i+\'!\';
}

void registerChar (char ch) {
   charCount++;
   if (islower(ch))
       lwrcaseCount++;
  

   else if (isupper(ch))
       uprrcaseCount++;
  

   else if (isdigit(ch))
       digitCount++;
  

   else if (ispunct(ch))
       specialCount++;

   count[ch - \'!\'] ++;
}

void sort() {
   int i,j,temp;
   char tempChar;
   for (i=0; i<94-1; i++)
       for (j=0; j<94-1-i; j++)
           if (charCount[j] < charCount[j+1]) {
               temp = charCount[j];
               charCount[j] = charCount[j+1];
               charCount[j+1] = temp;
               tempChar = charSym[j];
               charSym[j] = charSym[j+1];
               charSym[j+1] = tempChar;
           }
}

void printStat() {
   int i, count = -1;
   printf(\"%d charecters\ \",charcount);
   printf(\"lowercase=%d and uppercase=%d and digit=%d and special=%d\ \",lwrcaseCount, uprcaseCount, digitCount, specialCount);
   sort();
   for (i=charCount; i>0; i--){
  

   for (i = 0; i < 94; i++) {
       if (count!=charCount[i]) {
           count = charCount[i];
           if (count)
               printf(\"\ Charecters occuring %d times: \",count);
           else
               printf(\"\ Charecters not found in input: \");
       }
       printf(\"%c \",charSym[i]);
   }
}

nt main() {
   char *str;
   int i, l;
   initialize();
   str = //take input your way;
   l = length(str);
   for(i=0; i<l; i++)
       registerChar(str[i]);
   printStat();
   return 0;
}
//THE CODE IS SELF EXPLANATORY
//See ASCII table if needed and discover that above-mentioned characters are found between 41 and 126

We are writing in C and I can\'t get this homework done, can anyone offer assistance? Ever wonder what is in a file? Ever wonder how many times each character a
We are writing in C and I can\'t get this homework done, can anyone offer assistance? Ever wonder what is in a file? Ever wonder how many times each character a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site