Permission Denied trying to run this. C code

0 Joey Bananas · June 5, 2015

#include       

#define CHARACTER       'C'
#define INTEGER         'I'
#define FLOAT           'F'

struct generic_tag{
        char type;

union shared_tag{
        char    c;
        int     i;
        float   f;
        } shared;
};

void print_function(struct generic_tag generic);

int     main(void){

        struct generic_tag var;

        var.type = CHARACTER;
        var.shared.c = '$';
        print_function(var);

                var.type = FLOAT;
                var.shared.f = (float) 12345.67890;
                print_function(var);

                        var.type = 'x';
                        var.shared.i = 111;
                        print_function(var);

        printf("\nAddress of var: %p", &var);

        return 0;
}

void    print_function(struct generic_tag generic){
                printf("\nThe generic value is...");

                switch(generic.type){
                case CHARACTER: printf("%c\n", generic.shared.c);
                                break;
                case INTEGER:   printf("%d\n", generic.shared.i);
                                break;
                case FLOAT:     printf("%f\n", generic.shared.f);
                                break;

                default:        printf("an unknown type: %c\n",
                                                generic.type);
                                break;
        }
}



I have been fiddling around with struct/unions. All has been going well until I started messing with pointers. Why does this complie but not let me run it? I thought about sudo the compile. But I thought I better not. 

Post a Reply

Replies

Oldest  Newest  Rating
0 c student · June 6, 2015
works fine for me
0 Joey Bananas · June 6, 2015
Weird. 

On eOS. That shouldn't matter though.
  • 1

C

107,322 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator