Strona główna > Zapis do pliku > Dodawanie do pliku C

Dodawanie do pliku C

19 Styczeń 2011 Dodaj komentarz Go to comments
//Dodawanie, wyszukiwanie, zapis studentów i ich ocen do bazy danych(pliku)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct student
{
    char imie[10];
    char nazwisko[10];
    int wiek;   
    struct{
        int wdp;
     }oceny;
}student_typ[20];

void dodaj(void)
{
      int i,n;
      printf("Ilu studentow dodac?: ");
      scanf("%d" , &n);
      for(i=0 ; i<n ; i++)
      {
          printf("Podaj imie:     ");
          scanf("%s", &student_typ[i].imie);
          printf("Podaj nazwisko:   ");
          scanf("%s" , &student_typ[i].nazwisko);
          printf("Podaj ocene z wdp:    ");
          scanf("%d" , &student_typ[i].oceny.wdp);
          printf("\n");
      }
}

void profil(int i)
{
   printf("%s " , student_typ[i].imie);
   printf("%s " , student_typ[i].nazwisko);
   printf("(%d)\n" , student_typ[i].oceny.wdp);
   printf("\n\n");
}

void szukaj_studenta(void)
{
   int i;
   int szukanie=0;
   char nazwisko[10];
   printf("Podaj nazwisko studenta: ");
   scanf("%s" , &nazwisko);

   for (i=0;i<20;i++)
   {
       if(!strcmp(nazwisko , student_typ[i].nazwisko))
        {
             profil(i);
             szukanie=1;  
        }
        if (!szukanie)
        {
        printf("Nie znaleziono!\n\n");
        break;
        }
   }
}      

void zapisz(void)
{
      FILE *plik;
      if((plik=fopen("dane" , "wb"))==NULL)
      {
          printf("Blad otwarcia\n");
          exit(1);
      }
      if(fwrite(student_typ, sizeof(student_typ) , 1 , plik)!=1)
          {
              printf("Blad zapisu!\n");
              exit(1);
          }
      fclose(plik);
    }

int main(void)
{
      int i=0,x;
      int liczba;
      while (i==0)
      {
          printf("1.Dodaj studenta\n2.Zapis do pliku\n3.Wyszukaj
          studenta\n4.Zakoncz\n\n");
          printf("Twoj wybor:  ");
          scanf("%d" , &x);
          switch(x)
          {
               case 1:dodaj();break;
               case 2:zapisz();break;
               case 3:szukaj_studenta();break;
               case 4:i=2;break;
               default:printf("Zle dane!\n\n");break;
          }
      }

 return 0;
}

 

  1. 12 Marzec 2013 o 11:35 pm

    It’s in fact very complicated in this active life to listen news on Television, thus I just use web for that reason, and obtain the most up-to-date news.

  2. 12 Sierpień 2013 o 4:10 am

    Actually when someone doesn’t be aware of then its up to other viewers that they will assist, so here it takes place.

  3. 14 Listopad 2013 o 12:40 am

    It’s remarkable to pay a visit this web site and reading the views of all colleagues regarding this paragraph,
    while I am also zealous of getting know-how.

  4. 22 Listopad 2013 o 7:51 pm

    I take pleasure in, result in I found just what I used to be looking for.
    You have ended my four day long hunt! God Bless you man.
    Have a nice day. Bye

  5. 4 Styczeń 2014 o 7:04 pm

    I like the helpful info you provide in your articles.

    I’ll bookmark your blog and check again right here regularly.

    I am somewhat certain I’ll be told many new stuff proper right here!
    Best of luck for the next!

  6. 28 Styczeń 2014 o 1:29 am

    Order some best sushgi in orlando florida delicious appetizers.
    If the toppings are not made of a variety of heartyy traditional entrees.
    All of these things is not like the other.
    The Tudor England at Thornbury Castle conjures backk imaes of the long gone days of Henry VIII and Anne
    Boleyn. During the quarter we recognized $500, 000. Once tney get used to thee relationship’s rhythm, their natural eatung tendencies will once again settle into place.

  7. 15 Lipiec 2016 o 2:09 am

    Hi there! I could have sworn I’ve been to this blog before but fter cheking
    through skme off the post I realized it’s new to
    me. Anyhow, I’m definitly glad I found it and I’ll be book-marking and checking bacck frequently!

  8. 1 Listopad 2016 o 5:52 pm

    Havе ʏou ever thouցht about creating an ebook оr guest authoring оn other websites?
    I have a blog based ߋn tһе sаme іnformation you discuss and
    would love tto Һave you sare some stories/information. I know my viewers ԝould ѵalue yߋur ѡork.
    ӏf you’re evenn remotely interested, feel free tο shoot
    me an email.

  1. No trackbacks yet.

Skomentuj

Wprowadź swoje dane lub kliknij jedną z tych ikon, aby się zalogować:

Logo WordPress.com

Komentujesz korzystając z konta WordPress.com. Log Out / Zmień )

Zdjęcie z Twittera

Komentujesz korzystając z konta Twitter. Log Out / Zmień )

Facebook photo

Komentujesz korzystając z konta Facebook. Log Out / Zmień )

Google+ photo

Komentujesz korzystając z konta Google+. Log Out / Zmień )

Connecting to %s

%d bloggers like this: