![]() ![]() One approach is to check the contents char by char. In checking the terminating condition, as shown earlier, word = "quit" will not work as this will not compare array contents (both in C and Java). keep on reading until a word "quit" is read in, followed by any character.define a function int occurrence (char word(), char c) which returns the number of occurrences of c in word. This function is similar to s.indexof() method in Java. define a function int indexOf(char word(), char c) which returns the index (position of the first occurrence) of c in word. You should NOT call strlen() library function in your function. ![]() This function is similar to strlen(s) C library function shown earlier, and s.length() method in Java. define a function int length (char word ) which returns the number of characters in word (excluding the trailing character '\0').Assume each input word contains no more than 20 characters (so what is the minimum capacity the array should be declared to have?). define a char array to hold the input word.Observe how the string" "helloWorld" is modified and shortened at the char level. download program lab3occur.c and start from there.Problem A Reading and manipulating character arrays (20 pts) Specification Write an ANSI-C program that reads from standard input a word (string with no spaces) followed by a character, and then outputs the word, the number of characters in the word, and the index of the character in the word.
0 Comments
Leave a Reply. |