/* * File: lab10.c * Description: This is a template program for CS102 Spring 11 class. * This template is divided in four parts which constitute Lab 10. * Created: Sunday November 15, 2009 * Author: Marco Bernasconi (mberna7@uic.edu) * * Modified by: INSERT HERE YOUR NAME!! */ #include #include #define WORD_LENGTH 10 #define NUM_WORDS 10 int containsSubstring(const char *, const char *); int countVowels(const char *); int tokenize(const char *, char [][WORD_LENGTH]); int main() { char line[NUM_WORDS * WORD_LENGTH]; int i = 0; // 1. Read a line from the standard input and store it in the 'line' variable printf("1. Enter a line of text: "); /* HINT: take a look at the getchar() function */ // 2. Count the number of vowels in that line printf("2. In the line \'%s\' there are %d vowels\n", line, countVowels(line)); // 3. Parse the line and print out a word per line char words[NUM_WORDS][WORD_LENGTH]; int numWords = tokenize(line, words); printf("3. The %d words in the line are:\n", numWords); for (i = 0; i < numWords; i++) { printf("\t\'%s\'\n", words[i]); } // 4. Read a substring from the standard input and print all words that contain that substring printf("4. Enter a substring: "); char substring[WORD_LENGTH]; scanf("%s", substring); for (i = 0; i < numWords; i++) { if (containsSubstring(words[i], substring) == 0) { printf("\t\'%s\' contains \'%s\'\n", words[i], substring); } } return 0; } /* * Determine if the string s1 contains any occurrence of the string s2. * If one occurrence is found it returns 0, otherwise it returns -1. */ int containsSubstring(const char *s1, const char *s2) { int result = -1; return result; } /* * Determine the number of occurrences of a vowel in the string s1. */ int countVowels(const char *s1) { int counter = 0; return counter; } /* * Store all the words that are in the string s1 into the array s2. * Return the number of words found in the string s1. */ int tokenize(const char *s1, char s2[][WORD_LENGTH]) { int wordCounter = 0; return wordCounter; }