www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback


/*
          Copyright (c) 1996, SAS Institute Inc.
             Unpublished - All Rights Reserved
                   Language: C
         Prints out each unique word and its count.
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "wrdcnt2c.h" /* Wordcount2 include file    */

wordlist *head;

   /*------------------MAIN------------------------------*/
   /* Open input file and call readin                    */
   /*                                                    */
void main()
{
FILE *input;         /* input file */

if ((input=fopen("ddn:DATAIN","r")) != NULL)
                     /* open input file */
   readin(input);
else {
   fprintf(stderr,"Error: cannot open input file\n");
   exit(1);
   }
exit(0);
}

   /*------------------READIN----------------------------*/
   /* Read in words from input file.                     */
   /* Words are truncated if > MAXLEN.                   */
   /* Call insertw - inserts words in wordlist           */
   /* Call printlst - print final wordlist               */
   /*                                                    */
void readin(FILE *f)

{
int c,wordlen=0,inword=FALSE;
char wordstrg(|MAXLEN+1|);

head=(wordlist *)malloc(sizeof(wordlist));
head->next=NULL;
   /* allocate a block of memory of size wordlist       */
   /* return a pointer to the block                     */
   /* assign the pointer to head (head of the wordlist) */
   /* set head->next to NULL (no items in the list)     */
   /* read in characters from input file                */

while((c=fgetc(f)) != EOF) {
      /* alphabetic character test */
   if (isalpha(c)) {
      inword=TRUE;
      if (wordlen next);
}

Copyright (c) 2000 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement