Lecture 8: Getting ready for program 1: unsigned chars and command line inputs
Reading command line inputs
Key points:
- To read command line input, define main with two input arguments: number of command line arguments and list of command line arguments, e.g.
int main(int argc, char** argv) { } - Here
argcis the number of command line argument sandargvis an array of character pointers containing all of the arguments. - To read one argument as an integer, use
atoi(argv[1]).atoiis part of the standard library, so use#include <stdlib.h>
Unsigned char data type
Key points:
chardata type is actually one of many integer data types (see “Intege Types” here: https://www.tutorialspoint.com/cprogramming/c_data_types.htm)unsigned charstores integers 0 to 255 using only 1 byte- use
%hhuplaceholder in strings forprintfandscanf