Well since I’ve already covered Ternary statements, I’ll show an example of doing the word count using only” if” statements for the logic, they are exactly like the ternary statement, but easier to follow. I’ll get back to the while statements later. For now how about a VK74A Ninga web page Control Panel? I have one on my site at http://w4qed.hamshack.info:8080
Ok here is some code that is the word count program using “if” statements. I haven’t been able to find the while code as yet. I’ve had some major system crashes including my backup systems.
/*
wcp6.c – Word Count Plus
by: Ben Miller WB8LGH
date: 22-Feb-91
Usage: wc < inputfilename.ext > (outputfilename.ext || device)
*/
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
char *version = “Version 01.01.06”; /* Current version, Major, Minor */
char *release_date = “(c) 01-March-91”; /* release date */
char *TITLE = “Word Count Program”; /* name of Program */
main(argc,argv)
int argc;
char **argv;
{
int wc;
long alphas,vowels,consonants,lowers,words,uppers,digits,spaces,lines,counts; /* counters */
char ch; /* input character */
char c; /* same input character forced lower case */
/* everything to zero */
alphas=vowels=consonants=lowers=uppers=digits=spaces=lines=counts=words=0l;
wc = 0;
fprintf(stderr,”\n\n%*c%s”,(80-strlen(TITLE))/2,’ ‘,TITLE);
fprintf(stderr,”\n%*c%s”,(80-strlen(version))/2,’ ‘,version);
fprintf(stderr,”\n%*cCopyright %s\n\n”,(80-strlen(release_date))/2-5,’ ‘,release_date);
setmode(fileno(stdin),O_BINARY); /* force read of entire file */
time_0();
while ((ch = getchar()) != EOF) { /* now get the characters from file */
c = tolower(ch);
if (ch==0x0a) {
lines++;
spaces++;
} else {
if (isspace(ch)) {
if (wc >=1) {
words++;
spaces++;
} else
spaces++;
wc = 0;
} else {
if (isalpha(ch)) {
alphas++;
wc++;
if (islower(ch))
lowers++;
else
uppers++;
if (c==’a’|| c==’e’|| c==’i’ || c==’o’|| c==’u’)
vowels++;
else
consonants++;
} else
if (isdigit(ch))
digits++;
else
counts++;
}
}
}
fnsh_1();
fprintf(stdout,”\n%*cType%*cCount”,6,’ ‘,30,’ ‘); /* show results */
fprintf(stdout,”\n%*calpha%*c%10ld”,6,’ ‘,24,’ ‘,alphas);
fprintf(stdout,”\n%*clower-case%*c%10ld”,6,’ ‘,19,’ ‘,lowers);
fprintf(stdout,”\n%*cupper-case%*c%10ld”,6,’ ‘,19,’ ‘,uppers);
fprintf(stdout,”\n%*cconsonants%*c%10ld”,6,’ ‘,19,’ ‘,consonants);
fprintf(stdout,”\n%*cvowels%*c%10ld”,6,’ ‘,23,’ ‘,vowels);
fprintf(stdout,”\n%*cwhite-space%*c%10ld”,6,’ ‘,18,’ ‘,spaces);
fprintf(stdout,”\n%*cdigits%*c%10ld”,6,’ ‘,23,’ ‘,digits);
fprintf(stdout,”\n%*clines%*c%10ld”,6,’ ‘,24,’ ‘,lines);
fprintf(stdout,”\n%*cwords%*c%10ld”,6,’ ‘,24,’ ‘,words);
fprintf(stdout,”\n%*cmiscellaneous%*c%10ld”,6,’ ‘,16,’ ‘,counts);
fprintf(stdout,”\n%*ctotal characters%*c%10ld\n\n”,6,’ ‘,13,’ ‘,(alphas + spaces + digits + counts));
fflush(stdout); /* flush buffer */
}
/*
end of code
*/