Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #define MAX 30 // maximum word characters are 30
- void lastword_func(char *last_word); // func declaration
- int
- main()
- {
- char last_word[MAX];
- lastword_func(last_word);
- if (strcmp(last_word, "defbbasda") == 0)
- printf("right %s\n", last_word);
- else
- printf("wrong guess\n");
- return (0);
- }
- void
- lastword_func(char * last_word)
- {
- unsigned char i, state = 0;
- i = 0;
- int c;
- while ((c = getchar()) != EOF && i < MAX) {
- if (c == ' ' || c == '\t' || c == '\n')
- state = 1;
- else {
- if (state == 1) {
- i = 0;
- state = 0;
- }
- last_word[i++] = c;
- }
- }
- last_word[i] = '\0';
- }
Advertisement
Add Comment
Please, Sign In to add comment