Question
C programming I am having trouble getting the functions to work in main. Below is my code. QUES 6: Write a function named countBlanks that
C programming I am having trouble getting the functions to work in main. Below is my code.
QUES 6: Write a function named countBlanks that counts and returns the integer number of blank spaces that appear in a string provided as a parameter. (Recall that a blank space is a character: )
QUES 7: Write the C statements that could be added to the main function to define a string named sentence that could be used for the previous problem, using your choice of words. Call the function countBlanks, passing sentence as a parameter. Display the returned result.
QUES 8: Define a function named biggest that locates and returns the largest value in a 1-d array of floating point values that is provided as a parameter.
QUES 9: Write the C statements that could be added to the main function to declare a 1-d array of floating point values named miles of length 4 that could be used for the previous problem. Initialize the array using your choice of values. Call the function biggest, passing the array as a parameter and display the returned result.
/*QUESTION 6*/ //Define function that counts & returns int number of blank spaces in a string int countBlanks (char sent []) { printf("Please type a sentence. "); scanf(" %c", &sent); int i; //loop control variable int len = strlen(sent); //array length variable int count = 0; //counter variable for (i = 1; i < len; i++) { if (sent[i] == ' ') { count++; }//End of if statement
}//End of for loop
return count;
}//End of countBlanks function
/*QUESTION 8*/ //Define biggest to locate largest value in array float biggest(int vals[], int len) { float largestVal = vals[0]; int j; //len = strlen(vals); for(j = 0; j < len; j++) { if (vals[j] > largestVal) { largestVal = j; } //end of if statement } //end for loop
return largestVal; }//End of biggest function
int main (void)
{
/*QUESTION 7*/ int numOfBlankSpaces; char sentence[100]; numOfBlankSpaces = countBlanks(sentence); printf("The number of blank spaces in string sentence is: %d ", numOfBlankSpaces);
/*QUESTION 9*/ //Declaring miles and setting values to check code char miles[4] = {1.0, 2.0, 3.0 , 4.0}; int length = strlen(miles); float biggestFloatingPointValue = biggest(miles, length);
printf("The biggest floating point value in the miles array is: %.3f ",biggestFloatingPointValue );
return 0; }//End of main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started