c-test/src/main.c

114 lines
2.3 KiB
C
Raw Normal View History

2024-11-04 14:44:45 -05:00
#include <stdio.h>
// #include <stdint.h>
#include <inttypes.h>
// My code
#include "math_functions.h"
#include "hello.h"
#include "struct_test.h"
#include "pointer_test.h"
#include "read_file.h"
2024-11-04 14:44:45 -05:00
// Test
// https://stackoverflow.com/questions/8666378/detect-windows-or-linux-in-c-c
#ifdef _WIN32
#include <Windows.h>
#endif
#include "stdbool.h"
2024-11-04 14:44:45 -05:00
// TODO Move this into a different project.
#ifdef _WIN32
void guiTest(){
}
#endif
// #define _FLIP_BOOLS
// Hmm, very evil
#ifdef _FLIP_BOOLS
// This is just madness, inverting the boolean values :P
#define true FALSE
#define false TRUE
// #define true (rand() % 2)
// #define false (rand() % 2)
#endif //_FLIP_BOOLS
2024-11-04 14:44:45 -05:00
// TODO Look into making a gtk C program
// https://www.geeksforgeeks.org/how-to-create-gui-in-c-programming-using-gtk-toolkit/
// Print out the memory addresses for each item in an array.
void array_test() {
// https://www.tutorialspoint.com/cprogramming/c_memory_address.htm
// Int array
int numbers[5] = {1,2,3,4,5};
int i = 0;
printf("numbers = %p\n", numbers);
do {
printf("numbers[%u] = %p\n", i, (void *)&numbers[i]);
i++;
} while (i < 5);
printf("sizeof(numbers) = %lu\n", sizeof(numbers));
}
// https://www.tutorialspoint.com/cprogramming/c_ternary_operator.htm
void check_even_odd(int num) {
(num %2 == 0) ? printf("%d is even\n", num) : printf("%d is odd\n", num);
}
2024-11-04 14:44:45 -05:00
int main() {
char welcomeMsg[] = "Welcome to KCNet";
// printf(welcomeMsg);
uint16_t test = -2;
// array_test();
// for (int i=0; i<5; i++) {
// check_even_odd(i);
// }
// check_even_odd(1);
// new_struct();
read_file("test.txt");
2024-11-04 14:44:45 -05:00
// This doesn't work
// uint16_test();
//? 65534? Where is that number coming from
// https://stackoverflow.com/questions/29112878/how-do-i-printf-a-uint16-t
// printf("Number: %u", (unsigned int)test);
// https://stackoverflow.com/questions/12120426/how-do-i-print-uint32-t-and-uint16-t-variables-value
// printf("Number: %" PRIu32, test);
// mathFunctions();
// print_struct();
int i = 22222;
int* i_ptr = &i;
// pointer_madness(i_ptr);
#ifdef _FLIP_BOOLS
bool testb = false;
if (testb) {
printf("True");
} else {
printf("False");
}
#endif //_FLIP_BOOLS
2024-11-04 14:44:45 -05:00
// printf_example();
return 0;
}