Fedora Linux Support Community & Resources Center
  #1  
Old 17th November 2011, 03:26 AM
JoeNapoleon Offline
Registered User
 
Join Date: Oct 2011
Location: Wuhan , China
Posts: 22
linuxfirefox
Exercise 1-11 , how to run the program to test the word count program?

How are you?
in the book The C programming language.
Exercise 1-11
How would you test the word count program? What kinds of input are most likely to uncover bugs if there are any?

There is a program written by Gregory Pietsch

Code:
#include <assert.h>
#include <stdio.h>

int main(void)
{
    FILE *f;
    unsigned long i;
    static char *ws = " \f\t\v";
    static char *al = "abcdefghijklmnopqrstuvwxyz";
    static char *i5 = "a b c d e f g h i j k l m "
                      "n o p q r s t u v w x y z "
                      "a b c d e f g h i j k l m "
                      "n o p q r s t u v w x y z "
                      "a b c d e f g h i j k l m "
                      "n\n";

    /* Generate the following: */
    /* 0. input file contains zero words */
    f = fopen("test0", "w");
    assert(f != NULL);
    fclose(f);

    /* 1. input file contains 1 enormous word without any newlines */
    f = fopen("test1", "w");
    assert(f != NULL);
    for (i = 0; i < ((66000ul / 26) + 1); i++)
        fputs(al, f);
    fclose(f);

    /* 2. input file contains all white space without newlines */
    f = fopen("test2", "w");
    assert(f != NULL);
    for (i = 0; i < ((66000ul / 4) + 1); i++)
        fputs(ws, f);
    fclose(f);
 
    /* 3. input file contains 66000 newlines */
    f = fopen("test3", "w");
    assert(f != NULL);
    for (i = 0; i < 66000; i++)
        fputc('\n', f);
    fclose(f);
 
    /* 4. input file contains word/ 
     *    {huge sequence of whitespace of different kinds}
     *    /word 
     */
    f = fopen("test4", "w");
    assert(f != NULL);
    fputs("word", f);
    for (i = 0; i < ((66000ul / 26) + 1); i++)
        fputs(ws, f);
    fputs("word", f);
    fclose(f);

    /* 5. input file contains 66000 single letter words,
     *    66 to the line 
     */
    f = fopen("test5", "w");
    assert(f != NULL);
    for (i = 0; i < 1000; i++)
        fputs(i5, f);
    fclose(f);

    /* 6. input file contains 66000 words without any newlines */
    f = fopen("test6", "w");
    assert(f != NULL);
    for (i = 0; i < 66000; i++)
        fputs("word ", f);
    fclose(f);

    return 0;
}
When you run the program, it shows nothing.
How can I run the program to test the word count program? Should I input a file?
Thank you very much.

Last edited by JoeNapoleon; 17th November 2011 at 03:34 AM. Reason: repair
Reply With Quote
  #2  
Old 17th November 2011, 03:59 AM
jpollard Online
Registered User
 
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,782
linuxfedorafirefox
Re: Exercise 1-11 , how to run the program to test the word count program?

Hmm. This program doesn't do anything to the terminal, it just generates test files.

Is this a bit of homework?
Reply With Quote
  #3  
Old 17th November 2011, 04:37 AM
JoeNapoleon Offline
Registered User
 
Join Date: Oct 2011
Location: Wuhan , China
Posts: 22
linuxfirefox
Re: Exercise 1-11 , how to run the program to test the word count program?

No, I learned the c programming language myself, but I think maybe I should do exercise after every section.
But I was not able to program the complete program , because I can not master the whole language grammar and lack of experience. So I decided to download the exercise solution file in internet which is written by American. So firstly I tested them and watched the program construction to learn. Thank you for replying me.
Reply With Quote
Reply

Tags
111, count, exercise, program, run, test, word

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile a Pulseaudio test program? Bagger Programming & Packaging 4 23rd February 2009 06:19 PM
System stability affected by program after program has been closed...? DennyCrane Using Fedora 0 29th June 2008 01:53 AM
Reading output from program, called inside another program clearer Programming & Packaging 2 20th February 2008 08:52 AM
program for test my hdd jestemradek Hardware & Laptops 0 9th April 2006 01:21 PM


Current GMT-time: 20:29 (Monday, 28-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat