“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 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 converts π / 7 to an angle in degrees and assigns the result to a variable.arrow_forwardWrite a statement that produces a random number between 1 and 100 and stores it in the variable luckyNumber.arrow_forward
- Write 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_forwardExtend 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_forward
- e variable. Express your solution as an int y-11-13 yarrow_forwardWrite a statement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forwardThe following condition evaluates to True when the string stored in the strLetter variable is lowercase letter; otherwise, it evaluates to False. Please complete the code. If strLetter Like ....... Thenarrow_forward
- لغة اسمبلي 1- Write a program to read a letter in lower case thenconvert this letter to upper case and print it (To convertfrom lower to upper subtract from the value 20h). 2. Write a program that asks the user to enter grades forthree courses (Course A, Course B. Course C) then Prints the average of these grades. 3- Write a program to convert from Celsius to Fahrenheit Tf=Tc*9/5+32arrow_forwardQ\ Write a program that converts a temperature from Celsius to Fahrenheit. It should (1) prompt the user for input, (2) read a double value from the keyboard, (3) calculate the result, and (4) format the output to one decimal place. For example, it should display "24.0 C = 75.2 F". Here is the formula. Be careful not to use integer division! F = C ×9/5+32arrow_forwardThe date June 10, 1960 is special because when we write it in the following format, the month times the day equals the year: 6/10/60 Write a program that asks the user to enter any date in the format specified above (month/day/2-digit-year). (It is very important that the input is in the correct format, typed all at once, all on one line, by the user. See the hints below.) The program should then determine whether the month times the day is equal to the year. If so, it should display a message saying the date is magic. Otherwise it should display a message saying the date is not magic. in C++ Do not use any string variables in this assignment. Hints: Read the three data into three separate int variables. Even though the user will be typing only one line of input, you will be using the extraction operator multiple times to read that input. I strongly suggest that you review lesson 2.9 before starting on this assignment. To make your job easier, we will specify that it is still a valid…arrow_forward
- Np Ms Office 365/Excel 2016 I NtermedComputer ScienceISBN:9781337508841Author:CareyPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning