1: |
Which conversion specifier would you use with printf() to format an integer as a double? Write down the full syntax required to convert the integer 33.
|
2: |
How would you pad the conversion you effected in question 1 with zeroes so that the part before the decimal point is four characters long?
|
3: |
How would you specify a precision of two decimal places for the floating-point number you have been formatting in the previous questions?
|
4: |
Which function would you use to determine the length of a string?
|
5: |
Which function would you use to acquire the starting index of a substring within a string?
|
6: |
Which function would you use to extract a substring from a string?
|
7: |
How might you remove white space from the beginning of a string?
|
8: |
How would you convert a string to uppercase characters?
|
9: |
How would you break up a delimited string into an array of substrings?
|
| |
A1:
| The conversion specifier f is used to format an integer as a double:
printf("%f", 33 );
|
| |
A2:
| You can pad the output from printf() with the padding specifier—that is, a space or a zero followed by a number representing the number of characters by which you want to pad:
printf("%04f", 33 );
|
| |
A3:
| The precision specifier consists of a dot (.) followed by a number representing the precision you want to apply. It should be placed before the conversion specifier:
printf("%4.2f", 33 );
|
| |
A4:
| The strlen() function returns the length of a string. |
| |
A5:
| The strstr() function returns the starting index of a substring. |
| |
A6:
| The substr() function extracts and returns a substring. |
| |
A7:
| The ltrim() function removes white space from the start of a string. |
| |
A8:
| The strtoupper() function converts a string to uppercase characters. |
| |
A9:
| The explode() function splits up a string into an array. |