Thread: c programming help

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    8

    c programming help

    Hey guys I am teaching myself the C language and came across a program assignement that i think would be helpful to know how to do. Here is the assignement :

    Write a C program that will read a series of lines of input text (each input text line will not exceed 80 characters in length) and determine the number of each unique "word"s found in the input. While finding the words, several statistics about the words and text are to be accumulated.


    A "word" is defined for this assignment as a series of non-white-space characters with leading and trailing punctuation characters removed. You are to consider punctuation characters to be all printing characters except letters, digits, and the space. C can automatically identify punctuation characters using the ispunct() function.

    Note that punctuation characters inside a word (such as teacher's) are considered part of the word, and sequences of numbers (like 1234) would also be considered valid words, based on the assignment's definition of a word.



    The program should determine each word found in a series of input lines, and accumulate the following characteristics about the words:
    • The number of short-length words (words with a length less than 6).
    • The number of medium-length words (words with a length greater than 5 but less than 12).
    • The number of long-length words (words with a length greater than 11).
    • The number of capitalized words.
    • The number of common words ("the", "of", "a", "is", "that", "are"), without worrying about case. Treat the words case-insensitively. Accumulate one total for all of the common words listed.
    • The number of sentences (a sentence is considered to be (for this assignment) to be indicated by a word that has either a period, exclamation point, or a question mark someone in its trailing punctuation).
    After all of the words have been determined, display a summary report of each of the characteristics described above.
    • You code should follow consistent indentation, use well-chosen variable names, and be written so as to be easily read.
    • You should NOT include printf() prompt statements in your code as you will be reading data from a file, using Linux redirection (./a.out < datafile.dat).

    I would greatly appreciate if someone could show me the code on how to do this as it would be very useful to study so I further my knowledge of the language. Thank you!

    Here is the text for the file that is supposed to be used.

    The teacher announced: "This is a simple example
    showing several sentences of text." The students
    where instantaneously amazed!


    With surprise, the teacher's dog stood up and barked
    "Ruff! Ruff!! Ruff!!!" The students were surprised
    and burst into applause, much to the teacher's chagrin.


    That is all, folks! [86 and out].
    Last edited by hallo; 11-08-2011 at 11:50 AM.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    8
    I would try and start this code but I'm not really sure how to go about doing so as I have always used the printf command and never have used data from a file or used the Linux redirection

  3. #3
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    There is nothing really there to learn about C programming. This has to do with the shell/command prompt you're using. All the assignment is saying there is, instead of prompting the user to enter lines of text, like so:
    Code:
    printf("Enter a line of text: ");
    fgets
    You drop the printf, so you only call fgets or whatever. The redirection operator < basically treats the contents of the file to the right of it as though it is input typed by the user. In the example given, ./a.out < datafile.dat, the contents of datafile.dat are fed to a.out as though they were typed by the user line by line. Since the teacher is using redirection here, and there is no user interacting with your program, there is no need to actually prompt for input, hence no printf statements for that. Your code still has to use printf to output the statistics however.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About Device Driver Programming And Socket Programming
    By pritesh in forum Linux Programming
    Replies: 6
    Last Post: 01-23-2010, 03:46 AM
  2. Replies: 1
    Last Post: 08-19-2007, 03:55 AM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM