Home
Netbeans Eclipse Qt Java
Games
College of Engineering Aeronautics and Astronautics Agricultural and Biological Engineering Biomedical Engineering Chemical Engineering Civil Engineering Construction Engineering and Management Electrical and Computer Engineering Engineering Education Engineering Professional Education Environmental and Ecological Engineering Industrial Engineering Materials Engineering Mechanical Engineering Nuclear Engineering
EPICS (Engineering Projects In Community Service) First-Year Engineering Program First-Year Engineering Honors Program Global Engineering Program Minority Engineering Program Professional Practice (Co-Op) Program Women in Engineering Program
College Administration Schools Programs All Groups All People ECN Webmail
Purdue Home

Exercise 1

Counting Characters in a File

Due Date - January 20, 2012 @ 2pm

Introduction

      Often, the inputs that programs need will come from files.  It is therefore important to know how to open and access files in C; in fact, managing files is one of the three outcomes of ECE 264.  This exercise will introduce you to the various functions in C that accomplish these tasks.

Assignment

      Write a program that reads a file and prints out the number of times different alphabetic characters appears in the file (disregarding case, i.e. 'a' is the same as 'A'), as well as the total number of characters in the file.

Output Code

    You can download the code for the expected output here.

Specifications

  1. The name of file to be examined will be given as a (single) command-line argument.
  2. Upper and lower case forms of the characters should be treated the same.
  3. Non-alphabetic characters (i.e. outside of the range A to Z and a to z) should be ignored.

Submission Procedure

   Create a zip file containing the following files

  • ex1.c

To create a zip file in Linux terminal, type

> zip ex1.zip ex1.c

(> is the terminal prompt. Do not type it.)

   and then submit the zip file (i.e. ex1.zip) to the course grading website

Tips and Hints

We will be discussing how to solve this exercise during the lectures.  However, as a hint, some of the file operation functions you will be needing to solve this problem include fopen, fclose, and fgetc.

Example

    Let's say an example file called example1.txt that contains the pharse "There is no place like home".  The resulting output should be as followed

     > ex1 example1.txt

    a 1
    b 0
    c 1
    d 0
    e 5
    f 0
    g 0
    h 2
    i 2
    j 0
    k 1
    l 2
    m 1
    n 1
    o 2
    p 1
    q 0
    r 1
    s 1
    t 1
    u 0
    v 0
    w 0
    x 0
    y 0
    z 0
    Total count - 22