“atol” function:
In C++, the predefined function “atol” is used to convert a string value into a long integer value; it passes a string literal or character array as an argument and it converts the received value into a long integer value; it takes only one parameter as an argument.
- If the argument value contains nonconvertible contents combined with the integer value then the values will be ignored while converting.
- In same way, the function will return “0” when the values can’t be able to convert into double data type.
Syntax:
Syntax for “atol” function is as follows:
long int atol (const char* n);
In the above statement,
- “long int” represents the return type of the function.
- “atol” represents the name of the function.
- “const char*” represents the data type of the passing argument.
- “n” is a string variable which is required to be converted.
Example:
The example for the “atol” function is as follows:
//change the string literal to a long type value
long n = atol ("123456 hello");
In the above line, the string literal “123456 hello” is passed as an argument to “atol” and it returns the converted value that is “123456”; here the “atol” function ignores the whitespace and the nonconvertible value “hello”.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
- Write a statement that converts PI to an angle in degrees and assigns the result to a variable.arrow_forwardWrite a single scanf statement that reads user-entered time (three integers) and discards the user-entered characters between the numbers, in order, for hour (hh), minute (mm), and second (ss). For example, the user may enter the time as 12:23:21 or 12 23 21 or 12, 23, 21.arrow_forwardWhich string method does the following: To capitalize the initial character of the string.arrow_forward
- Which expression for XXX causes the code to output the strings in alphabetical order? (Assume the strings are lowercase) if (XXX) { printf("%s %s\n",firstString, secondString); } else { printf("%s %s\n",secondString, firstString); }arrow_forwardWrite a statement that converts π / 7 to an angle in degrees and assigns the result to a variable.arrow_forwardCreate a string variable and print the following information: Length of string Characters from 3rd to 7th Convert all characters to lower casearrow_forward
- Given a String variable named brand that has been declared and initialized, write the statement needed to create a new integer variable named numChars that contains the number of characters in the String. int numChars =arrow_forwardWrite a for statement to display first 5 even numbers (for example, 2, 4, 6, 8, 10)Use the variable count as the counter variable within the statement.arrow_forwardIn an output statement, the newline character may be a part of the string. (Mark the statements as true or false.)arrow_forward
- Extend to cast the double to an integer, and output that integer. Enter integer: 99 Enter double: 3.77 Enter character: z Enter string: Howdy 99 3.77 z Howdy Howdy z 3.77 99 3.77 cast to an integer is 3arrow_forwardString user_input is read from input. If user_input starts with 'G', then output 'String starts with G'. Otherwise, if all the characters in user_input are numbers, then output 'All numbers'. If none of the above are true, output 'No condition fits'.arrow_forward7. Read input an integer from the user and print whether it is "Negative"/"Positive" using the ternary operator. Programming Language: PHP MacBook Air 80 F5 F6 F7 F1 F2 F3 F4arrow_forward
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage