Lesson 17

ArtyArty
2 min read

Variable-length argument length

  • Is when we have functions that have unspecified number of arguments (eg. int printf(const char *format, ...);)

  • We must use variable argument headers stdarg.h.

  • We must use the following macros va_start, va_arg, va_list, va_end.

Command line arguments

  • int main(int argc, char * argv[]){} argc is the number of arguments, argv is a list of pointers to strings. (eg. ./program arg1 arg2argc == 3, argv == {“./program”, “arg1”, “arg2“})

CLI redirecting

  • Redirect input into program uses the redirect input symbol < (eg. sum < input)

  • Normally program output is displayed in screen, redirection grabs said input and sends it somewhere else.

  • Redirecting output into another program uses the pipeline symbol | (eg. random | input)

  • Redirect output into program uses the redirect output symbol > (eg. hello > out)

  • Redirect output appending it to another program using the append output symbol >> (eg. hello >> out)

File processing (need to practice)

rbRead an existing file
wbCreate binary file for writing. Discards current content if file exists
abAppends content to end of file. Open or create file in binary format.
rb+Open existing binary file for reading and writing
wb+Create binary file for update. Discards current content if file exists
ab+TODO

Program termination (need to practice)

  • You will need the stdlib.h module.

  • You can use the atexit function to register a function upon a successful termination program

  • takes an argument which is a pointer to a function with no arguments

Volatile

  • the volitile type qualifier may indicate that the variable may be changed by another program or by the computer’s hardware

Suffixes for integer constants

  • Specifying the types of integer and floating-point constants:

    • u or U for an unsigned integer

    • l or L for a long integer

    • ul, lu, UL or LU for an unsigned long integer

Suffixes for Floating-Point constants

  • Integer constant is not suffixed, its type is determined by the first type capable of storing a value of that size

  • Suffixes are

    • f or F for a float

    • l or L for a long double

0
Subscribe to my newsletter

Read articles from Arty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arty
Arty