17.05.2013 Views

Tutorial de Apuntadores y Arreglos en C - Cimat

Tutorial de Apuntadores y Arreglos en C - Cimat

Tutorial de Apuntadores y Arreglos en C - Cimat

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sin embargo, esta notación no es muy usada y los creadores <strong>de</strong> C nos han brindado la posibilidad <strong>de</strong> utilizar<br />

una sintaxis alternativa y con el mismo significado, la cual sería:<br />

st_ptr -> edad = 63;<br />

Con esto <strong>en</strong> m<strong>en</strong>te, veamos el sigui<strong>en</strong>te programa.<br />

PROGRAMA 5.2<br />

/* Program 5.2 from PTRTUT10.HTM 6/13/97 */<br />

#inclu<strong>de</strong> <br />

#inclu<strong>de</strong> <br />

struct ficha{<br />

char nombre[20]; /* nombre */<br />

char apellido[20]; /* apellido */<br />

int edad; /* edad */<br />

float salario; /* salario */<br />

};<br />

struct ficha mi_ficha; /* <strong>de</strong>finimos mi_ficha <strong>de</strong>l tipo<br />

estructura ficha */<br />

void show_name (struct tag *p); /* prototipo <strong>de</strong> la función */<br />

int main(void)<br />

{<br />

}<br />

struct ficha *st_ptr; /* un apuntador a una estructura<br />

<strong>de</strong>l tipo ficha */<br />

st_ptr = &mi_ficha; /* apuntamos el apuntador a mi_ficha */<br />

strcpy(mi_ficha.apellido,"J<strong>en</strong>s<strong>en</strong>");<br />

strcpy(mi_ficha.nombre,"Ted");<br />

printf("\n%s ",mi_ficha.nombre);<br />

printf("%s\n",mi_ficha.apellido);<br />

mi_ficha.edad = 63;<br />

show_name (st_ptr); /* Llamamos a la función pasándole el puntero */<br />

return 0;<br />

21

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!