Cyber Security
gcc lab1.c lab1_helper.c -o lab1
lab1.c:
#include <stdio.h>
#include <stdlib.h>
#include "lab1_helper.h"
/*
* Calculates the sum of consecutive numbers from start
* to end
(not including `end`).
* Parameters:
* start - an integer defining the starting value of the series
* end - an integer defining the stopping point of the series.
*
* Return: the total summation
*
*/
long int arithmeticSum(long int start, long int end) {
long int total = 0;
for (long int i = start; i < end; i++) {
total += i;
}
return total;
}
/*
* Takes in two integers as input.
* Calculates the arithmetic sum between those to integers.
* Mallocs an integer array, and writes the two integer inputs to the array.
*
* If the program doesn't receive exactly 2 arguments as input,
* the program should print "Invalid number of arguments.\n", and then exit with
* error code 1
.
*
*/
int main(int argc, char* argv[]) {
long int arg1 = strtol(argv[1], 0, 0);
long int arg2 = strtol(argv[2], 0, 0);
long int sum = arithmeticSum(arg1, arg2);
printf("Arithmetic Sum between %d and %d is: %d.\n", arg1, arg2, sum);
long int* arr = malloc(1000 * sizeof(int));
*(arr ) = 0;
*(arr + 1) = 100;
free(arr);
printf("Malloc'd data for arg1 %li and %li .\n", arr[0], arr[1]);
return 0;}