Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- typedef struct {
- char etunimi[256];
- char sukunimi[256];
- int ika;
- }Henkilo;
- void etsiJaTulosta( Henkilo [], int );
- void luepois(void);
- int main( void ){
- Henkilo henkilot[4] = {{"Kalle", "Kehveli", 57 },
- {"Uuno", "Valkky", 21 },
- {"Liisa", "Liimatainen", 21},
- {"Kalle", "Kuulianen", 57}};
- etsiJaTulosta( henkilot, 4 );
- return 0;
- }
- void etsiJaTulosta( Henkilo henkilot [], int maara ) {
- int i;
- char etunimi[256];
- printf("Anna etsittavan henkilon etunimi > ");
- fgets(etunimi, 256, stdin);
- //Käsitellään saatu nimi ja tyhjennetään tarvittaessa lukupuskuri
- if ( etunimi[strlen(etunimi) - 1] == '\n') {
- etunimi[strlen(etunimi) -1] = "\0";
- }
- else {
- luepois();
- }
- for(i=0; i < maara; i++){
- if( henkilot[i].etunimi == etunimi ){
- printf("%s %s %d vuotta\n", henkilot[i].etunimi, henkilot[i].sukunimi, henkilot[i].ika);
- }
- }
- }
- void luepois(void) {
- while(getc(stdin) != "\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement