3

I have a homework assignment to write a class that defines a type with "typedef"

according to the assignment, the type's name must be "complex" with lowercase c, and it must sit in complex.h file

however, i am developing this assignment in xcode, and this type is already defined there by objective c.

how can i make xcode favor my type and my file, over the default one, without renaming any of the files and object types ?

complex.h

#ifndef complex_complex_h
#define complex_complex_h



typedef struct complex complex;

struct complex{

    double real;
    double imaginary;

};


 complex A;
 complex B;
 complex C;
 complex D;
 complex E;
 complex F;


void read_comp (char * complexName, double real, double imaginary);
void print_comp (char * complexName);
#endif

complex.c

#include <stdio.h>
#include <string.h>
#include  "complex.h"

  complex get_complex_from_name(char * complexName);
  complex notFound;

 complex get_complex_from_name(char * complexName){
    if(strcmp(complexName,"A")==0 ){
        return A;
    }
    if(strcmp(complexName, "B")==0){
        return B;
    }

    if(strcmp(complexName, "C")==0){
        return C;
    }
    if(strcmp(complexName, "D")==0){
        return D;
    }
    if(strcmp(complexName, "E")==0){
        return E;
    }
    if(strcmp(complexName, "F")==0){
        return F;
    }
    return notFound;
}

void read_comp(char *complexName, double real, double imaginary){
    struct complex comp = get_complex_from_name(complexName);
    comp.real = real;
    comp.imaginary = imaginary;
}

void print_comp(char *complexName){
    struct complex comp = get_complex_from_name(complexName);
    printf("%s=%f+(%f)i",complexName,comp.real, comp.imaginary);
}

compiler throws errors, doesnt know which complex i mean

Lena Bru
  • 13,521
  • 11
  • 61
  • 126

2 Answers2

1

Get the XCode Command Line Tools and compile your code as straight C on the command line using clang.

Community
  • 1
  • 1
japreiss
  • 11,111
  • 2
  • 40
  • 77
0

You should be able to use #undef complex to undefine the Objective C implementation of complex and then #define your own.