| Topic: |
Religions > Bible |
| User: |
"Simon" |
| Date: |
29 Jan 2004 03:59:19 PM |
| Object: |
C grammar revised. |
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_input(char *input);
void get_output(const char *input, char *output);
void display_output(const char *output);
int main()
{
char input[256], output[256];
while (get_input(input) && strcasecmp(input, "quit")) {
get_output(input, output);
display_output(output);
}
return 0;
}
int get_input(char *input)
{
printf("%s", "Enter word or \"QUIT\" to quit:\n");
int retval = scanf("%.256s", input);
return retval != EOF && retval > 0;
}
void get_output(const char *input, char *output)
{
if (!strcasecmp(input, "your")) {
strcpy(output, "Belonging to, or of, you.\n");
} else if (!strcasecmp(input, "you're")) {
strcpy(output, "Short for \"you are\".\n");
} else {
strcpy(output, "Invalid input.\n");
}
}
void display_output(const char *output)
{
printf(output);
}
/*
* Any suggestions are welcome!
*
* Credits:
* The Ghost In The Machine
*/
.
|
|
| User: "The Ghost In The Machine" |
|
| Title: Re: C grammar revised. |
30 Jan 2004 03:00:16 PM |
|
|
In comp.os.linux.advocacy, Simon
<some_spare_id@yahoo.com>
wrote
on 29 Jan 2004 13:59:19 -0800
<82ca3381.0401291359.3eb1905d@posting.google.com>:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_input(char *input);
void get_output(const char *input, char *output);
void display_output(const char *output);
int main()
{
char input[256], output[256];
while (get_input(input) && strcasecmp(input, "quit")) {
get_output(input, output);
display_output(output);
}
// An improvement. The system will no longer fail oddly on EOF.
// However, an obvious enhancement might be to accept arguments
// on the command line:
// $ grammar your
// Your/You're: the first means 'belonging to, or of, you";
// the second is short for "You are".
// although there's the problem that
// $ grammar you're
// > (?)
// > (??!?)
// > (?!@$#@*#$@!!!)
// > (CTRL/C)
// $
// might be slightly confusing.
return 0;
}
int get_input(char *input)
{
printf("%s", "Enter word or \"QUIT\" to quit:\n");
int retval = scanf("%.256s", input);
return retval != EOF && retval > 0;
// This needs work, though it wil function as written.
// The main problem is that the main loop will prompt
// multiple times if one enters more than one word here.
// For this sort of program that may not be a big issue.
}
void get_output(const char *input, char *output)
{
if (!strcasecmp(input, "your")) {
strcpy(output, "Belonging to, or of, you.\n");
} else if (!strcasecmp(input, "you're")) {
strcpy(output, "Short for \"you are\".\n");
} else {
strcpy(output, "Invalid input.\n");
}
}
void display_output(const char *output)
{
printf(output);
}
/*
* Any suggestions are welcome!
*
* Credits:
* The Ghost In The Machine
*/
Heh, thank you, thank you, and I want to thank everyone
of the little people for...oh, wait, this isn't the
Academy, is it?
Darn... :-)
--
#191,
It's still legal to go .sigless.
.
|
|
|
|

|
Related Articles |
|
|