you are viewing a single comment's thread
view the rest of the comments
[–] 2 points 2 months ago (1 child)

Before trying to learn and use the standard library, I'd advise you to write a few simple functions yourself:

  1. void print_until(const char* str, char c) - print every character in str until you see c or null (Note: Don't print the c or null, which should ensure that a str that only contains a \0 doesn't crash.)
  2. const char* print_until_2(const char* str, char c) - as before, but return the pointer to where you found c or null
  3. void print_delimited_by(const char* str, char delimiter, char separator) - use print_until_2 in a while-loop, don't print the delimiter, but do print a separator.

For example, print_delimited_by("1;2;3",';',',') should print 1,2,3.

Finally, void num_delimited_by(const char* str, char del) - like print_delimited_by, but add a number before every output, and use newline as the separator.

These fundamental string exercises will give you a solid foundation for understanding oantby's explanations about the standard library. Note that no memory allocation is necessary.

  • source
  • hideshow 1 child comment
  • load more comments (1 reply)