/* This program is to test an ability to make an input functio that will operate on "my" terms */ #include #include #include #define EOF '~' #define arsize 512 int main(void) { char ch[arsize], prevchar; int arrnum = 0, chdel = 0, newlines = 0; int s_nums = 0, s_spc = 0, s_punct = 0, s_lower = 0, s_alpha = 0; printf("Please enter some text (512 char max)a as a test of my input function.\n"); printf("Type %c to echo the text and end the program.\n", EOF); do { ch[arrnum] = getch(); prevchar = ch[arrnum]; if(ch[arrnum] == '~') { ch[arrnum] = '\0'; break; } else if(arrnum + 2 == arsize&&ch[arrnum] != '\b') { ch[arrnum - 1] = '\0'; putchar('\a'); } else if(ch[arrnum] == '\b') { printf("\b \b"); arrnum--; chdel++; continue; } else if(ch[arrnum] == 13) { ch[arrnum] = '\n'; arrnum++; newlines++; } else arrnum++; if(arrnum + 2 < arsize) putchar(ch[arrnum-1]); if(isdigit(ch[arrnum-1]) != 0&&prevchar != '\b') s_nums++; if(isalpha(ch[arrnum-1]) != 0&&prevchar != '\b') s_alpha++; if(islower(ch[arrnum-1]) != 0&&prevchar != '\b') s_lower++; if(ispunct(ch[arrnum-1]) != 0&&prevchar != '\b') s_punct++; if(isspace(ch[arrnum-1]) != 0&&prevchar != '\b') s_spc++; } while(ch[arrnum-1] != EOF&&arrnum < arsize); printf("\n\nYou entered:\n%s\n", ch); printf("\nWhich is %d characters read, %d characters deleted, and %d newlines\n", arrnum, chdel, newlines); printf("\nAnd some more specific info:\n"); printf(" You entered %d lowercase characters, %d digits, %d punctuation marks,\n %d uppercase characters, and %d alphabetic characters\n", s_lower, s_nums, s_punct, (s_alpha - s_lower), s_alpha); printf("Well, that's my test! I hope it worked!\n"); while(kbhit() != 0) getch(); printf("Press any key to continue..."); getch(); return 0; }