“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 (9th Edition)
- Write a statement that declares a string named city with value Chicago.arrow_forwardWrite a statement that will convert the Base 3 string 21201 to a numeric integerand store the result in the variable numarrow_forwardWrite a statement that converts PI to an angle in degrees and assigns the result to a variable.arrow_forward
- Write a statement that displays the number of characters in string s.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_forwardWrite a statement that will convert the C-string “100000” to a long and store the result in the variable num.arrow_forward
- Which string method does the following: To capitalize the initial character of the string.arrow_forwardWhich 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_forward
- Create a string variable and print the following information: Length of string Characters from 3rd to 7th Convert all characters to lower casearrow_forwardWrite a statement that produces a random number between 1 and 100 and stores it in the variable luckyNumber.arrow_forwardGiven 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_forward
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:Cengage