In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of April 7th
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #05 exercise sheet]
In this problem you should submit a file containing the function as described (without any main function). Inside the function do not print anything that was not asked!
Petyr "Littlefinger" Baelish, known for his cunning and sharp mind, has intercepted several secret messages containing a mix of letters, digits and other symbols. To decode potential hidden information, he wants to understand how many digits are within the message, since they could be related to important dates, coordinates, or quantities.
Write a function int digits(char str[]) that receives a string str and returns the amount of characters of str that are digits.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |str| < 100 | Length of the string |
You should submit a .c
file containing the requested function, without any main function and without printing anything. You can however create additional methods, if you need them.
Mooshak will use the following code to link to your function, read the inputs and call your method, printing its result.
#include <stdio.h> #define MAX_SIZE 100 int digits(char []); int main(void) { // Read amount of strings int n; scanf("%d", &n); // Read n strings and for each one call the digits function char str[MAX_SIZE]; for (int i=0; i<n; i++) { scanf("%s", str); printf("digits(\"%s\") = %d\n", str, digits(str)); } return 0; }
Example Input | Example Output |
5 pedro p3dr0 P0wn 1234567 19year98 |
digits("pedro") = 0 digits("p3dr0") = 2 digits("P0wn") = 1 digits("1234567") = 7 digits("19year98") = 4 |