Question: The code dosn't compile i need help fixing it #include #include #include // Function to accept valid size of character array and a string //

The code dosn't compile i need help fixing it

#include #include #include

// Function to accept valid size of character array and a string // Returns the length of string int getString(char *str) { // To store size entered by the user int size; // Loops variable int x; // Accepts the size of the string printf(" Enter the size of the string: "); scanf("%d", &size);

// Loops till valid size entered by the user do { // Checks if size entered by the user is greater than 0 // and less than or equals to 20 then come out of the loop if(size > 0 && size <= 20) break; // Otherwise invalid size else { // Accept the size again printf(" Please enter again: "); scanf("%d", &size); }// End of else }while(1); // End of do - while loop

// Dynamically allocates memory to the string of entered size str = malloc(sizeof(int) * size); // Clears the console input fflush(stdin);

// Accepts a string printf(" Please enter the string: "); gets(str);

// Loops till valid string entered by the user do { // Checks if length of the string is greater than the user entered size if(strlen(str) > size) { // Display error message printf(" The string entered is longer than the allowed size.");

// Accepts the string again printf(" Please enter a valid string: "); gets(str); }// End of if condition

// Otherwise calls the function to check valid string // If the function returns -1 invalid string // Otherwise valid string else if(checkString(str, strlen(str)) == -1) { // Accepts the string again printf(" Please enter a valid string: "); gets(str); }// End of else if condition

// Otherwise valid string else { // Display the string and stops the loop printf(" String = %s", str); break; }// End of else }while(1); // End of do - while loop

// Returns the length of the string return strlen(str); }// End of function

// Function returns -1 for invalid string, Otherwise returns 1 for valid string int checkString(char* str, int len) { // Loops variable int x;

// Loops till length of the string for(x = 0; x < len; x++) // Checks if the current character of the string is between 97 and 122 // (ASCII value of 'a' and 'z') if(str[x] >= 97 && str[x] <= 122) // Subtracts 32 from current character to convert it to upper case str[x] = str[x] - 32;

// Loops till length of the string for(x = 0; x < len; x++) { // Checks if current character is less than 65 (ASCII for 'A') // or greater than 90 (ASCII for 'Z') then return -1 if(str[x] < 65 || str[x] > 90) return -1; }// End of for loop

// Returns 1 for valid string return 1; }// End of function

// main function definition int main() { // Declares a character pointer and initializes to NULL char *str = NULL; // Calls the function to accept a valid string // Function return length of the string and displays the length printf(" which is size %d", getString(str)); }// End of main function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!