C Saved Program: calm-terrain

facebook share

Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdbool.h>

struct IntArray {
    int numbers[];
    int length;
    bool good;
};

struct IntArray newIntArray(int l) {
    struct IntArray arr;
    if (l <= 0) {
        printf("Error: Trying to create array of size 0 or less.");
        arr.good = false;
    } else arr.good = true;
    arr.length = l;
    arr.numbers[l];
    return arr;
}

void destroyIntArray(struct IntArray arr) {
    if (arr.good == false) {
        printf("Error: Invalid array.");
    }
}

int readIntArrayAt(struct IntArray arr, int n) {
    if (arr.good == false) {
        printf("Error: Invalid array.");
    }
    if (n >= arr.length || n < 0) {
        printf("Error: Trying to read undefined index.");
        return 0;
    }
    return arr.numbers[n+1];
}

void writeIntArrayAt(struct IntArray arr, int n, int nn) {
    if (arr.good == false) {
        printf("Error: Invalid array.");
        return;
    }
    if (n >= arr.length || n < 0) {
        printf("Error: Trying to read undefined index.");
        return;
    }
    arr.numbers[n+1] = nn;
}

int main(void) {
    int *p;
    struct IntArray arr = newIntArray(5);
    
    char txt[] = "abcdefghij";
    char *zeiger = &txt[1];
    printf("%p\n", txt);
    printf("%p\n", &zeiger[4]);
    printf("%c\n", *zeiger);
    printf("%p\n", zeiger + 3);
    printf("%c\n", *(zeiger + 1 - 1));
    printf("%p\n", ++zeiger);
    printf("%c\n", *++zeiger);
    printf("%p\n", zeiger);
    printf("%c\n", --(*zeiger));
    printf("%c\n", *zeiger++);
    printf("%c (current)\n", /***/(&zeiger[1] - 1));
    printf("%c\n", *(zeiger - 3));
    printf("%c\n", *zeiger);
    printf("%c\n", zeiger[-1]);
    printf("%c\n", (zeiger + 1)[-1]);
    printf("%ld\n", zeiger - txt);
    
    return EXIT_SUCCESS;
}
Execute

Output

Press the execute button or CTRL + enter to run code.

Inputs