Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. /* tehdään rakenteesta globaali */
  4. struct henkilo{
  5. char etunimi[20+1];
  6. char sukunimi[20+1];
  7. char puhelin[20+1];
  8. };
  9.  
  10. int main(void)
  11. {
  12. struct henkilo hlotaulu[50];
  13. int tietoja, i;
  14. const char *tiedNimi = "luettelo.txt";
  15. FILE *fp;
  16.  
  17. /* haetaan tiedostosta tulostettavat tiedot */
  18. if((fp = fopen(tiedNimi,"r")) == NULL){
  19. printf("tiedoston %s avaaminen epäonnistui\n", tiedNimi);
  20. exit(1);
  21. }
  22. fscanf(fp,"%d", &tietoja);
  23. for(i=0;i<tietoja;i++){
  24. fscanf(fp,"%s %s %s",
  25. hlotaulu[i].etunimi, hlotaulu[i].sukunimi, hlotaulu[i].puhelin);
  26. }
  27. fclose(fp);
  28.  
  29. /* tulostetaan tiedot näytölle */
  30. for(i=0;i<tietoja;i++){
  31. printf("%s %s %s\n",
  32. hlotaulu[i].etunimi, hlotaulu[i].sukunimi, hlotaulu[i].puhelin);
  33. }
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement