String handling in C - new examples of extracting integers from a string
Archive - Originally posted on "The Horse's Mouth" - 2016-01-27 16:41:13 - Graham EllisA new example in C, reading in a line of text and parsing all the integers from it into an array - [here]. It uses
fgets to read a line from the user
strdup to take a copy of that line
strsep to read up to the next separator
strtol to convert a string to a (long) integer
strcmp to compare two strings
A slightly less advance pair of examples use
strlen to get the length of string
[here] and [here].