Results 1 to 19 of 19

Thread: fwrite

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Apr:2010
    Location: Veliko Tarnovo
    Posts: 19

    fwrite

    , , - , , , .
    Code:
    #include <stdio.h>
    #include <process.h>
    #include <ctype.h>
    struct knigi{
    	char zagl[80];
    	char avtor[80];
    	int godina;};
    	int a,b;
    FILE * wfile (char * nfile);
    void rfile (FILE * fp2, char * nfile2);
    void main() {
    	char name_f[13], * pn;
    	FILE * fp1;
    	pn=name_f;
    	printf("\n Vavedi ime na fayl: ");
    	gets (pn);
    	fp1=wfile (pn);
    	if (fp1!=NULL){
    		printf("Faylyt e syzdaden!\n");}
    	else {
    		printf("Faylyt ne e syzdaden!\n");
    		exit(1);}
    	//rfile(fp1,pn);
    	printf("Vavedete period na izdavane: \n");
    	printf("Ot: ");scanf("%d",&a);
    	printf("Do: ");scanf("%d",&b);
    }
    //funkciq za zapis/
    FILE * wfile (char * nfile){
    
    	FILE * pf;
    	struct knigi s ,* ps;
    	char ch;
    	ps=&s;
    	pf=fopen(nfile,"ab");
    	if(pf=NULL)
    	{printf("Fayl s ime %s ne move da se syzdade!\n",nfile);
    	exit(1);}
    	else
    	{printf("Fayl s ime %s e uspeshno syzdaden",nfile);
    	};
    	do
    	{printf("\n Zaglavie: ");
    	gets (s.zagl);
    	printf("Avtor: ");
    	gets(s.avtor);
    	printf("Godina na izdavane: ");
    	scanf("%d",&s.godina);
    	fwrite (ps,sizeof(s),1,pf);
    	while(ch=getchar()!='\n');
    	printf("\n Shte vavejdate li otnovo? Y/N: ");
    	ch=getchar();
    	fflush(stdin);}
    	while(toupper(ch)=='Y');
    	fclose(pf);
    	return(pf);}
    , new 1.exe encountered a problem and needs to close.

  2. #2
    Mire-x
    Join Date: Apr:2005
    Location: Sofia
    Posts: 763
    "if(pf=NULL)" -> "if(pf==NULL)"
    (10b) || !(10b)

  3. #3
    Registered User axi's Avatar
    Join Date: Aug:2013
    Location: Sofia
    Posts: 3,638
    fwrite, , NULL .
    if(pf==NULL) if(NULL==pf) =, , , .

  4. #4
    Registered User
    Join Date: Apr:2010
    Location: Veliko Tarnovo
    Posts: 19
    . . .
    Code:
    #include <stdio.h>
    #include <process.h>
    #include <ctype.h>
    struct knigi{
    	char zagl[80];
    	char avtor[80];
    	int godina;};
    struct knigi2{
        char zagl[80];
    	char avtor[80];
    	int godina;}knigi2[20];   
    	int a,b,i,n=0,k=0;
    FILE * wfile (char * nfile);
    void rfile (FILE * fp2, char * nfile2,int a,int b);
    void main() {
    	char name_f[13], * pn;
    	FILE * fp1;
    	pn=name_f;
    	printf("\n Vavedi ime na fayl: ");
    	gets (pn);
    	fp1=wfile (pn);
    	if (fp1!=NULL){
    		printf("Faylyt e syzdaden!\n");}
    	else {
    		printf("Faylyt ne e syzdaden!\n");
    		exit(1);}
    	printf("Vavedete period na izdavane: \n");
    	printf("Ot: ");scanf("%d",&a);
    	printf("Do: ");scanf("%d",&b);
    	rfile(fp1,pn,a,b);
    }
    //funkciq za zapis/
    FILE * wfile (char * nfile){
    
    	FILE * pf;
    	struct knigi s ,* ps;
    	char ch;
    	ps=&s;
    	pf=fopen(nfile,"ab");
    	if(pf==NULL)
    	{printf("Fayl s ime %s ne move da se syzdade!\n",nfile);
    	exit(1);}
    	else
    	{printf("Fayl s ime %s e uspeshno syzdaden",nfile);
    	};
    	do
    	{printf("\n Zaglavie: ");
    	gets (s.zagl);
    	printf("Avtor: ");
    	gets(s.avtor);
    	printf("Godina na izdavane: ");
    	scanf("%d",&s.godina);n++;
    	fwrite (ps,sizeof(s),1,pf);
    	while(ch=getchar()!='\n');
    	printf("\n Shte vavejdate li otnovo? Y/N: ");
    	ch=getchar();
    	fflush(stdin);}
    	while(toupper(ch)=='Y');
    	fclose(pf);
    	return(pf);}
    //funkciq za chetene i sortirane//
    void rfile (FILE * fp2, char * nfile2,int a,int b){
          struct knigi s2, *ps2;
          struct knigi2 s3, *ps3;
          ps2=&s2;ps3=&s3;
          int nr;long int pos;
          fp2=fopen(nfile2,"rb");
          if(fp2==NULL){
                        printf("Faylyt ne moje da se otvori");
                        exit(1);}
          nr=fread(ps2,sizeof(s2),1,fp2);              
          while(nr==1){
                       for(i=0;i<n;i++){
                       if(s2.godina>=a||s2.godina<=b){
                          s3[i].zagl=s2.zagl;
                          s3[i].avtor=s2.avtor;
                          s3[i].godina=s2.godina;k++;
                          pos=ftell(fp2)-sizeof(s2);
                          nr=fread(ps2,sizeof(s2),1,fp2);}
                          else{pos=ftell(fp2)-sizeof(s2);k++;
                          nr=fread(ps2,sizeof(s2),1,fp2);}
    					  fclose(pf2);
         i=0;
         for(i=0;i<k;i++){                 
         printf("Zaglavie: %s, Avtor %s, Godina na izdawane: %d",s3[i].zagl,s3[i].avtor,s3[i].godina);}
    , - .

  5. #5
    Registered User axi's Avatar
    Join Date: Aug:2013
    Location: Sofia
    Posts: 3,638
    .

  6. #6
    Registered User
    Join Date: Apr:2010
    Location: Veliko Tarnovo
    Posts: 19
    , . : , , . , , ( ... ....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |