Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Error Activity
- /*** HINTS ***/
- // Everything above main is correct, no errors.
- // Main has 14 errors.
- // LoadArray has 8 errors.
- // PrintArray has 6 errors.
- // SequentialSearch has 7 errors.
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #define MAXSZ 100
- void LoadArray(int[], int);
- void PrintArray(int[], int);
- int SequentialSearch(int[], int, int);
- int main(void)
- {
- //Local Declarations
- int intAry(MAXSZ);
- int search = '0';
- //Local Statements
- rand(time());
- LoadArray(intAry[], MAXSZ)
- PrintArray{intAry*, MAXS};
- printf("Enter in an integer between 1 and 999 to search for: );
- scanf(" %d", search);
- if(SequentialSearch(intAry[], MAXSZ, search) = 0)
- {
- print("No items matched your search.\n");
- }
- return;
- }//end main
- void LoadArray(int aryIn[], int sz)
- {
- //Add a temp variable
- int tmp = 0;
- for(int i == 0; i < z; i+)//change the stopping point
- {
- aryIn{j} = srand() % 999 + 1;
- return 1;
- }//End function
- void PrintArray(int aryIn[], int sz)
- {
- char cntPerLine = 0;
- for(int i = 0; i < sz; i++, cntPerLine++)
- {
- printf("%4d",aryIn());
- if cntPerLine = 9)
- {
- printf("\n");
- cntPerLine = -1;
- }
- return;
- }//End function
- int SequentialSearch(int aryIn[], int sz, int search)
- {
- int nbrFound = 0
- for (int i = 0, i<sz, j++)
- {
- if(search == aryIn[j])
- {
- printf("Found an item at: %d\n" i);
- nbrFound-+;
- }
- }
- return nbrFound;
- }//end function
- Problem #1: Use osprey to practice for exam #3
- Compose a program and include the string.h library. In the program declare a
- character array and also initializes it to the value “December”. Declare a pointer of
- type char and initialize it to the value “January”. Declare a third item, a pointer to a
- char and initialize it to NULL. Compose 3 printf() statements to print the 3 strings
- you just declared to standard out along with %d the length of those strings using the
- string function strlen(). Did you get a segmentation fault? Why?
- Problem #2: Use osprey to practice for exam 3
- Compose a program that declares a character array and initialize the array to the
- value of the string “Mary had a little lamb”. Use a for loop to print the array to screen
- one character at a time backwards. Your for loop should determine when to stop by
- using the strlen() function. Recall that array indexing starts at 0.
- Now modify the program and when you declare and initialize the array, declare it
- using pointer notation like you did in problem 1. Did it work the same?
- Problem #3:
- Modify the previous problem to print the array to screen using printf() and the %s
- modifier. One method processes characters and one processes strings.
- Problem #4:
- Using the program from problem 2 you are tasked to determine if each letter
- entered by the user is a vowel or a consonant. Create a function called IsVowel()
- that takes a character and determines if it is a vowel by returning a Boolean value
- true or false to the caller. Your function should be able to verify both lower and
- upper case characters by using the character function islower() or isupper(). You
- will also need stdbool.h and ctype.h to your include files.
- Now in main, after the function calls to read the data into the array, create a loop
- that will print each character and the Boolean result of it is a vowel or not to output
- with a newline after each character. Comment out the former printing function that
- printed out the array previously. Given “Mary had a little lamb” your output should
- resemble the following:
- Enter a sentence up to 80 characters in length:
- Mary Had a Little Lamb
- M is consonent
- a is vowel
- r is consonent
- y is consonent
- H is consonent
- a is vowel
- d is consonent
- a is vowel
- L is consonent
- i is vowel
- t is consonent
- t is consonent
- l is consonent
- e is vowel
- L is consonent
- a is vowel
- m is consonent
- b is consonent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement