I thought that postfix increment or decrement were both really low priority; according to that chart, they're really high priority.
Am I confused about something here?
I guess my question is: in this instance, is ++ being interpreted as a prefix or postfix operator?
Also: I wasn't planning on using crap like this everyday in my code. This is deliberately mangled code for learning purposes.
By the way, the program is actually a really overdone solution to exercise 1-13 in K&R C, second edition. I was going to write a barebones solution(I'm going back through the book and doing EVERY exercise to train my hands to type code more comfortably), but I got bored halfway through and started adding stuff... you know, features'n'stuff.
Here's the end product:
Code:
#include <stdio.h>
#include <ctype.h>
#define MAXCOUNT 1500
#define MAXLEN 17
#define HOR 0
#define VERT 1
void countinput(void);
void helpmsg(int);
void printhor(void);
void printvert(void);
void helpmsg(int i)
{
if(i == 0) {
printf("Program produces histogram of word lengths in input.\n");
printf("Max word length is %d.\n", MAXLEN);
printf("Input anything, hit EOF control sequence to impliment counting.\n");
printf("Defaults to horizontal output, -v will force vertical output.\n");
printf("Options:\n");
printf("-v Output vertical graph.\n");
printf("-h Print this message.\n");
exit(0);
}
else if(i == 1) {
printf("Invalid option. Try -h for help.\n");
exit(0);
}
else if(i == 2) {
printf("Too many options. Try -h for help.\n");
exit(0);
}
else
printf("helpmsg: invalid argument.\n");
}
int charcnt[MAXLEN];
int main(int argc, char *argv[])
{
int i, scratch;
for(i = 0; i < MAXLEN; i++)
charcnt[i] = 0;
if(*++argv == NULL)
i = HOR;
else if(argc > 2)
helpmsg(2);
else if((*argv)[1] == 'h')
helpmsg(0);
else if(*++*argv == 'v')
i = VERT;
else
helpmsg(1);
countinput();
for(scratch = 0; scratch < MAXLEN; scratch++)
printf("%d", charcnt[scratch]);
putchar('\n');
if(i == HOR)
printhor();
else if(i == VERT)
printvert();
else {
printf("main: panic! i inequal to HOR or VERT!\n");
return 1;
}
return 0;
}
void countinput(void)
{
int i, c;
i = 0;
printf("Currently, all input(prior to hitting the EOF control sequence) must ");
printf("end with a space, carriage return, or other non-alphanumeric character.\n");
printf("We apologize for this inconvenience.\n");
while((c = getchar()) != EOF) {
if(c == ' ' || c == '\t') {
charcnt[0]++;
if(i > 0) {
if(charcnt[i] < (MAXCOUNT - 1))
charcnt[i]++;
i = 0;
}
}
else if(c == '\n') {
if(i > 0) {
if(charcnt[i] < (MAXCOUNT - 1))
charcnt[i]++;
i = 0;
}
}
else if(isalnum(c))
i++;
else {
if(i > 0) {
if(charcnt[i] < (MAXCOUNT - 1))
charcnt[i]++;
i = 0;
}
}
}
}
void printhor(void)
{
int i;
printf("Whtspc:");
for(i = 0; i < charcnt[0]; i++)
putchar('*');
printf("\nWordlen\n");
for(i = 1; i < MAXLEN; i++) {
printf("\n %d", i);
for(; charcnt[i] > 0; charcnt[i]--)
putchar('*');
}
printf("\n");
}
void printvert(void)
{
int i, j, k = 1;
printf("Whtspce");
for(i = 1; i < MAXLEN; i++)
printf("%7d", i);
putchar('\n');
i = 0;
while(i < MAXCOUNT && k < MAXLEN) {
printf("\n ");
i++;
k = 0;
j = 0;
while(j < MAXLEN) {
if(charcnt[j] > 0) {
printf(" * ");
charcnt[j]--;
}
else {
printf(" ");
k++;
}
j++;
}
}
putchar('\n');
}