diff --git a/string b/string new file mode 100755 index 0000000..65a3894 Binary files /dev/null and b/string differ diff --git a/string.c b/string.c new file mode 100644 index 0000000..f1ee6fd --- /dev/null +++ b/string.c @@ -0,0 +1,38 @@ +#include +#include + +int main() { + char *text, c; + int i = 0; + // this returns as a pointer + text = (char*) malloc(1 * sizeof(char)); + + printf("%p\n", text); + + // the size function will print out 8 bytes as it is + // calculating the size of the pointer, not the actual + // value itself. to do that, you gotta dereference it first + size_t size = sizeof(*text); + printf("%d\n", *text); + + printf("Size in bytes: %d bytes\n", (int)size); + + while(c = getc(stdin), c != '\n') { + text[i] = c; + i++; + + printf("===========================================\n"); + printf("Num of characters: %d\n", i); + printf("Current char: %c\n", text[i]); + printf("Address of current char: %p\n", &text[i]); + printf("===========================================\n\n"); + char* deez = realloc(text, i * sizeof(char)); + //printf("%s", deez); + } + + printf("The Text: %s\n\n", text); + + // size_t size = sizeof(*text); + // printf("Size in bytes: %d bytes\n", (int)size); + return 0; +} diff --git a/temp-input.c b/temp-input.c new file mode 100644 index 0000000..8abcc30 --- /dev/null +++ b/temp-input.c @@ -0,0 +1,15 @@ +#include + +#define LOWER 0 +#define STEP 20 +#define END 200 + +int main() { + float fahr, celsius; + + printf("Fahrenheit\tCelsius\n"); + for(fahr = LOWER; fahr <= END; fahr += STEP) { + celsius = (5.0/9.0) * (fahr - 32.0); + printf("%3.1f\t\t%3.1f\n", fahr, celsius); + } +} diff --git a/temp.c b/temp.c new file mode 100644 index 0000000..8abcc30 --- /dev/null +++ b/temp.c @@ -0,0 +1,15 @@ +#include + +#define LOWER 0 +#define STEP 20 +#define END 200 + +int main() { + float fahr, celsius; + + printf("Fahrenheit\tCelsius\n"); + for(fahr = LOWER; fahr <= END; fahr += STEP) { + celsius = (5.0/9.0) * (fahr - 32.0); + printf("%3.1f\t\t%3.1f\n", fahr, celsius); + } +} diff --git a/test/main b/test/main new file mode 100755 index 0000000..14c9213 Binary files /dev/null and b/test/main differ diff --git a/test/main.c b/test/main.c new file mode 100644 index 0000000..61a7bf0 --- /dev/null +++ b/test/main.c @@ -0,0 +1,50 @@ +#include + +int main() { + + // declaring and defining the 14 digit numbers + int digits[] = {3, 4, 2, 1, 5, 6, 8, 3, 1, 5, 1, 5, 6, 5}; + + // declaring the variable for the total of the first, third, fifth elements and so on... + int sum_odd; + + printf("=====================================\n"); + printf("First set of digits\n"); + printf("=====================================\n"); + // loop through the first, third, fifth element and so on + for(size_t i = 0; i < (sizeof(digits) / sizeof(digits[0])); i += 2) { + // multiplying the value of each element by 2 + digits[i] = digits[i] * 2; + printf("Element %d: %d\n", ((int)i + 1), digits[i]); + + // adding the value of the current element to the old sum_even value + sum_odd += digits[i]; + } + + // declaring the variable for second, forth, sixth elements and so on... + int sum_even; + + printf("\n"); + printf("=====================================\n"); + printf("Second set of digits\n"); + printf("=====================================\n"); + // loop through the second, forth, sixth digits and so on + for(size_t j = 1; j < (sizeof(digits) / sizeof(digits[0])); j += 2) { + // multiplying the value of each element by 2 + digits[j] = digits[j] * 2; + printf("Element %d: %d\n", ((int)j + 1), digits[j]); + + // adding the value of the current element to the old sum_even value + sum_even += digits[j]; + } + + // add the sum of sum_odd and sum_even together + int total = sum_odd + sum_even; + // print out the value + printf("\n"); + printf("=====================================\n"); + printf("Total: %d\n", total); + printf("=====================================\n"); + + return 0; +}