Basics of C/C++ Programming
Introduction
Lecturers
Rait Liiv: rait.liiv@itcollege.ee Janno Tomingas: janno.tomingas@itcollege.ee
C
Lectures
Practices
Practice 1
Console input/output
1. Write a program, that outputs "Hello, World!"
2. Write a program, that asks the user for a number and then writes the number back to the user
3. Write a simple calculator, that supports addition, subtraction, multiplication and division. The program should ask the user for two numbers and the operation to perform and output the result to the console.
Practice 2
Functions, pointers, out variables, function return values as success/error codes
Hint:
int add(int a, int b, int* out) { }
Hint:
int swap(int* a, int* b) { }
Hint:
int reverse(char* string, size_t length) { }
Hint:
int sort(int* string, size_t length) { }
Practice 3
File input/output, dynamic memory allocation
Hint:
Always close the file stream after you are done using it.
Make sure to check for error codes.
Hint:
Use "fseek", "ftell" and "rewind" to find out how large the buffer should be.
Make sure you have enough room for a null terminator.
Remember to free the allocated memory after calling malloc or calloc.
Make sure to check for error codes.