2012-03-22 10 views
1

なぜこのコードはDev-CPPで完全に実行されますが、Borland Turbo Cでは実行できませんか?ターボCで実行する場合構造体を使用した複素数加算

Input real part: Stack Overflow !

#include<stdio.h> 
#include<conio.h> 
#include<stdlib.h> 

struct complex 
{ 
int real; 
int img; 
}; 

typedef struct complex com; 
com read(com); 
com add(com,com); 
void show(com); 

void main() 
{ 
com c1,c2,c3; 
clrscr(); 
c1=read(c1); 
c2=read(c2); 
c3=add(c1,c2); 
show(c3); 
getch(); 
} 

com read(com c) 
{ 
printf("Input real part: "); 
scanf("%d",&c.real); 
printf("Input imaginary part: "); 
scanf("%d",&c.img); 
return (c); 
} 

void show(com c) 
{ 
printf("%d+%di",c.real,c.img); 
} 

com add(com c1,com c2) 
{ 
com c3; 
c3.img=c1.img+c2.img; 
c3.real=c1.real+c2.real; 
return (c3); 
} 
+0

ターボC - 1987年には本当に良いコンパイラです。自分で好きなだけ空けてください。 –

+0

上記の+1に+1してください。 – user138645

答えて

1

値によって構造体のメンバの周りを通過する不要を示しません。 以下を実行できます:

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

struct complex 
{ 
    int real; 
    int img; 
}; 

typedef struct complex com; 
void read(com *); 
void add(com,com, com *); 
void show(com); 

int main() 
{ 
    com c1,c2,c3; 
    read(&c1); 
    read(&c2); 
    add(c1,c2, &c3); 
    show(c3); 
    return 0; 
} 

void read(com *c) 
{ 
    printf("Input real part: "); 
    scanf("%d",&c->real); 
    printf("Input imaginary part: "); 
    scanf("%d",&c->img); 
} 

void show(com c) 
{ 
    printf("%d+%di",c.real,c.img); 
} 

void add(com c1,com c2, com *c3) 
{ 
    c3->img=c1.img+c2.img; 
    c3->real=c1.real+c2.real; 
} 
関連する問題