strtol Questions

17

Solved

In C, what is the most efficient way to convert a string of hex digits into a binary unsigned int or unsigned long? For example, if I have 0xFFFFFFFE, I want an int with the base10 value 429496729...
Shawanda asked 13/8, 2008 at 20:20

8

Solved

What is the difference between atol() & strtol()? According to their man pages, they seem to have the same effect as well as matching arguments: long atol(const char *nptr); long int strtol(...
Ballistics asked 25/9, 2010 at 5:48

1

Solved

#include <cinttypes> #include <string> #include <algorithm> #include <iostream> using namespace std; uint64_t descendingOrder(uint64_t a) { string str = to_string(a); sort...
Parrie asked 22/6, 2021 at 10:0

3

Solved

I can use the strtol function for turning a base36 based value (saved as a string) into a long int: long int val = strtol("ABCZX123", 0, 36); Is there a standard function that allows the inversi...
Gosser asked 15/1, 2020 at 12:26

1

Solved

The stoi function of c++ is defined as: int stoi(const std::string& str, std::size_t* pos = 0, int base = 10); as you can see, the base argument is defaulted as 10, so by default it could on...
Hasseman asked 4/9, 2019 at 14:0

1

Solved

Consider the following: #include <iostream> #include <cstdint> int main() { std::cout << std::hex << "0x" << std::strtoull("0xFFFFFFFFFFFFFFFF",0,16) << std:...
Handy asked 19/7, 2019 at 13:9

2

Solved

I've been trying to properly convert a char array to a long with strtol, check if there was an overflow or underflow and then do an int cast on the long. Along the way, I've noticed a lot of ...
Travis asked 18/3, 2016 at 1:7

5

Solved

I have been using std::atoll from cstdlib to convert a string to an int64_t with gcc. That function does not seem to be available on the Windows toolchain (using Visual Studio Express 2010). What i...
Bombe asked 7/7, 2011 at 12:25

2

I am writing a c program to be run on UNIX, and attempting to utilize the chmod command. After consulting the man pages, i know that chmod needs two parameters. first is the permission bits, second...
Cindacindee asked 27/11, 2013 at 9:9

3

Solved

I met some unexcepted result of strtol in c Here is the sample program. #include <string.h> #include <stdio.h> #include <stdlib.h> int main() { printf("%x\n", strtol("0xfffff...
Stoller asked 23/5, 2013 at 10:24

1

Solved

Here is how strtol has to be declared according to § 7.22.1.4 from C11 (n1570): #include <stdlib.h> long int strtol (const char *restrict nptr, char **restrict endptr, int base); As far...
Quicksand asked 14/2, 2013 at 16:39

4

Solved

I am really confused. I have to be missing something rather simple but nothing I am reading about strtol() is making sense. Can someone spell it out for me in a really basic way, as well as give an...
Crepuscular asked 10/2, 2013 at 2:30

3

Solved

This code seems to work as expected, populates an array of numbers using a single pointer #include <stdio.h> #include <ctype.h> #include <stdlib.h> int main(void) { int arr[4],...
Velmaveloce asked 19/12, 2012 at 11:59

6

Solved

Out of professional curiosity, what is the safest / fastest / most efficient way to compare two fully numeric strings in C? #include <stdio.h> #include <string.h> #include <stdlib.h...
Zinovievsk asked 17/6, 2011 at 18:8

6

Solved

I can do this: int main(int argc, char** argv) { unsigned char cTest = 0xff; return 0; } But what's the right way to get a hexadecimal number into the program via the command line? unsigned ...
Assail asked 29/1, 2010 at 15:15

4

The specification for strtol conceptually divides the input string into "initial whitespace", a "subject sequence", and a "final string", and defines the "subject sequence" as: the longest initi...
Proconsul asked 14/7, 2011 at 23:17

5

Solved

The following code does not give a warning with g++ 4.1.1 and -Wall. int octalStrToInt(const std::string& s) { return strtol(s.c_str(), 0, 8); } I was expecting a warning because strtol re...
Annalisaannalise asked 11/3, 2010 at 14:36
1

© 2022 - 2024 — McMap. All rights reserved.