Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. typedef struct {
  5. char etunimi[256];
  6. char sukunimi[256];
  7. int ika;
  8. }Henkilo;
  9.  
  10. void etsiJaTulosta( Henkilo [], int );
  11. void luepois(void);
  12.  
  13. int main( void ){
  14.  
  15. Henkilo henkilot[4] = {{"Kalle", "Kehveli", 57 },
  16. {"Uuno", "Valkky", 21 },
  17. {"Liisa", "Liimatainen", 21},
  18. {"Kalle", "Kuulianen", 57}};
  19.  
  20. etsiJaTulosta( henkilot, 4 );
  21.  
  22. return 0;
  23.  
  24. }
  25.  
  26. void etsiJaTulosta( Henkilo henkilot [], int maara ) {
  27.  
  28. int i;
  29. char etunimi[256];
  30.  
  31. printf("Anna etsittavan henkilon etunimi > ");
  32. fgets(etunimi, 10, stdin);
  33.  
  34. //Käsitellään saatu nimi ja tyhjennetään tarvittaessa lukupuskuri
  35. if ( etunimi[strlen(etunimi) - 1] == '\n') {
  36. etunimi[strlen(etunimi) -1] = "\0";
  37. }
  38. else {
  39. luepois();
  40. }
  41.  
  42. for(i=0; i < maara; i++){
  43.  
  44. if( henkilot[i].etunimi == etunimi ){
  45. printf("%s %s %d vuotta\n", henkilot[i].etunimi, henkilot[i].sukunimi, henkilot[i].ika);
  46. }
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement