Questions tagged [strtoul]

10 questions
8
votes
4 answers

How to use `strtoul` to parse string where zero may be valid?

According to the documentation for strtoul, regarding its return value... This function returns the converted integral number as a long int value. If no valid conversion could be performed, a zero value is returned. What if I'm parsing a…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
2
votes
5 answers

How can I convert hex encoded string to string in C efficiently

I need to convert hex encoded string like this: char hstr[9] = "61626364"; // characters abcd\0 Into "abcd" // characters as hex: 0x61 0x62 0x63 0x64 // hex "digits" a-f are always lowercase At this moment I wrote this function: #include…
Kamil
  • 13,363
  • 24
  • 88
  • 183
1
vote
1 answer

Passing two references to the same object in strtoul

The following code runs well under gcc 11.2.1: // test.c #include #include int main(int argc, char **argv){ char *msg; unsigned int val; msg = "1024 2048 4096 13"; while(*msg != '\0'){ val = strtoul(msg,…
onlycparra
  • 607
  • 4
  • 22
0
votes
1 answer

Strtoul Returns Wrong Output in Toy JVM Parser

I am trying to program a simple bit JVM with C. After reading the .class file with hex, I am trying to parse this file. char *get_bytecode(const char *filename) { FILE *fileptr = fopen(filename, "rb"); if (!fileptr) { fprintf(stderr,…
Levent Kaya
  • 33
  • 1
  • 1
  • 7
0
votes
1 answer

Cannot convert string to unsigned long in C

I convert string to unsigned long like this code. String t = "1667451600"; unsigned long ret; ret = strtoul(t,NULL,10); It show error like this. test:122:19: error: cannot convert 'String' to 'const char*' 122 | ret = strtoul(t,NULL,10); …
user58519
  • 579
  • 1
  • 4
  • 19
0
votes
1 answer

Is it possible to read character array elements into a struct using ```strtoul``` in C?

I'm working on a project for a class and I could use some guidance. I need to parse a character array into constituent parts - the specifications of which I am given - but I am unsure how to do so in C. I have been given a file and each page of the…
0
votes
1 answer

convert a string to unsigned long int of a given base: generic algorithm

As part of compiling proprietary driver code, I am forced remove inclusion of to address type conflicts arising with kernel include files. The last mile in getting the code compiled and linked successfully seems to be to replace the C…
Vinod
  • 925
  • 8
  • 9
-1
votes
3 answers

What does the 2nd argument in strtoul() function do?

According to this document, The second argument (char **endptr) seems to be a waste of space! If it is set to NULL, STRTOL seems to work its way down the string until it finds an invalid character and then stops. All valid chars read are then…
user366312
  • 16,949
  • 65
  • 235
  • 452
-1
votes
1 answer

Why is strtoul returning 0 from a "1" string?

I'm trying to compact a raster file in a way that is easy to read without GDAL library (my web server cannot install GDAL). Following this question, I'm doing the following to convert a raster's bytes (only 0 and 1 values) to bits: int main(int…
Rodrigo
  • 4,706
  • 6
  • 51
  • 94
-2
votes
2 answers

C - Convert Hex String to Int (with all 8 bits)

I'm trying to convert a hex string to an int (as hex still). I have it working, but there is a problem. If I enter the string "00000001" the result is 0x1. However, my function requires the full 8 bit values leading up to the 1. How can this be…
t0rxe
  • 95
  • 3
  • 14