estructura(struct)

azazel
01 de Julio del 2003
Hola,
Mi pregunta es la siguiente:
¿sintácticamente y semánticamente el siguiente código está bien expresado? yo tengo algunas dudas.

struct registro{
int a;
int b;
};
void main (void){
struct registro x;
struct registro *y;

x.a=5;x.b=10;
y=(struct registro *)malloc(sizeof(struct registro));
y->a=x.b;
y->b=x.a;
}
Por favor si no es correcto,¿alguien me puede decir cual es el fallo?Gracias.

Oliverio
01 de Julio del 2003
Suponiendo que obiaste los #include esta bien, pero podrias aorrarte todos los struct declarando tu estructura dentro de un typedef, de esta manera:
#include "stdio.h"
#include "malloc.h"

typedef struct{
int a;
int b;
} registro;

void main (void){
registro x;
registro *y;
x.a=5;x.b=10;
y=(registro *)malloc(sizeof(registro));
y->a=x.b;
y->b=x.a;
}