====== Lab04 - Arrays ====== ==== Task 1 ==== * A command-line argument specifies the number of integers to read (N) * Read N integers from standard input using [[https://cppreference.net/c/io/fscanf.html | scanf()]] to a variable-length array of size N * Print the array in the order entered * Sort the array in descending order using [[https://cppreference.net/c/algorithm/qsort.html | qsort()]] * Print the sorted array ==== Task 2 ==== * Write a program which allows the user to enter an “infinite” number of characters and will keep appending them to an array. * When they press ''P'', it will output the current array. * If they enter a character ''X'', it will convert the chars to upper case with [[https://cppreference.net/c/string/byte/toupper.html|toupper()]], print them and exit. * Use the [[https://cppreference.net/c/io/getchar.html|getchar()]] function to get letters from the command line. * You will need to use [[https://cppreference.net/c/memory/malloc.html|malloc()]] and [[https://cppreference.net/c/memory/realloc.html|realloc()]] to control the memory. * Don’t forget to use [[https://cppreference.net/c/memory/free.html|free()]] at the end to free the memory. * If you have time, add also sorting the chars alphabetically and lower case before upper case. ==== Valgrind ==== * use ''valgrind'' for memory leak detection * can detect forgotten allocated memory and the exact location of out-of-bound access * can report using uninitialized variables/memory * for better output, compile your program with ''-g'' flag * ''valgrind ./your-program'' ==== Documentation ==== * [[https://en.cppreference.com/w/c]] * Learn to understand the function declaration (the name, return type, and parameters) * The definition (code to be executed) might not always be available