170k views
1 vote
Write a function called countstuff () that takes as a parameter a character array, and returns an int. The prototype must be:

int countstuff (char s[]);
The array passed will be less than 1000 characters long. Your code should return a value indicating the number of uppercase characters, the number of lowercase characters, and the number of digits in the string. The number of uppercase characters should be returned in the millions places, the number of lowercase in the thousands places, and the number of digits in the units places (i.e. UUULLLDDD).

x=countstuff ("Space the final FRONTIER"); // x= 9012000
x=countstuff ("THERE ARE 4 LIGHTS"); // x=14000001
x=countstuff ("Send $1000 to Your Favorite ChArItY!!!"); // x=13012004

To force values into the millions, thousands, or units places, you can do something like
V = cntUp*1000000 + cntlow* 1000 + cntDigits

User Bodega
by
5.7k points

1 Answer

4 votes

Answer:

Please kindly go to the explanation part.

Step-by-step explanation:

The required function is written in Raw code below.

Function:

#include<stdio.h>

#include<ctype.h> //including required libraries

int countstuff(char s[]){ //Function countstuff

int cntUp=0,cntLow =0,cntDigits = 0,i=0,value; //declaring required variables

for(i=0;s[i]!='\0';i++){ //loop to iterate over the characters of string

if(isupper(s[i])){

cntUp++; //incrementing count of uppercase if it is uppercase character

}

else if(islower(s[i])){

cntLow++; //incrementing count of lowercase if it is lowercase character

}

else if(isdigit(s[i])){

cntDigits++; //incrementing count of digits if it is digit

}

}

value = cntUp*1000000 + cntLow*1000 + cntDigits; //counting value using formula given in question

return value; //returning the value

}

void main(){

char string[1000]; //declaring required variables

int value;

printf("Enter a String:");

scanf("%[^\\]s",string); //taking string as input

value = countstuff(string); //calling function

printf("The Value is : %d\\",value); //printing result

}

User KingsInnerSoul
by
5.4k points