Get premium membership and access questions with answers, video lessons as well as revision papers.

In the C++ standard library is the function strtol(), which has this prototype: long strtol|(const char*start, const **end, int base); The function cnverts the numeric string...

      

In the C++ standard library is the function strtol(), which has this prototype:
long strtol|(const char*start, const **end, int base);
The function cnverts the numeric string pointed to by start into a long integer. The number base of the numeric string is specified by base. Upon return, end points to the character in the string immediately following the end of the number. The long integer equivalent of the numeric string is returned. base must be in the range 2 to 38. However, most commonly, base 10 is used.
Create a function called mystrtol() that works the same as strtol() except that base is given the default argument of 10. Demonstrate that your version works correctly.

  

Answers


Davis
#include
#include
using namespace std;
long mystrtol(const char *s, char **end, int base = 10)
{
return strtol(s, end, base);
}
int main()
{
long x;
char *s1 ="100234 ";
char *p;
x = mystrtol(s1, &p,);
cout << "Base: "<x = mystrtol(s1, &p, 10);
cout << "Base 10: "<< x<< '\n';
x = (s1, &p); // use default base of 10
cout << "Base 10 byefault: "<< x<< '\n';
return 0;
}
Githiari answered the question on May 31, 2018 at 17:31


Next: Describe the advantages of being a social enterprise.
Previous: Most C++ compilers supply nonstandard functions that allow cursor positioning and the like. If a compiler supplies such functions, create a function called myclreol() using...

View More Computer Studies Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions