C problem...se megethos domhs

Someone ngeorg at nxmail.gr
Sat Jan 24 13:51:33 EET 2004


Xaire paides elpizo na eiste oloi kala!
Ksero oti den oi 2 parakato erothsoules den tha eprepe na erxontai se auth thn lista apla ksero oti edo arketoi apo esas exoun idea apo C kai sunepos mpas kai mporeite na dosete kamia idea. Auto pou thelo na kano einai na blepo to megethos tou arxeiou mou to opoio periexei domes. Me ton tropo pou brhka sto net pairno to megethos tou arxeiou se bytes.

1) o tupas pou egraspe ton kodika bazei os 2o orisma sthn fseek (poso tha metakinhthei apo thn SEEK_END)  to 0L ...exei kaneis kamia idea giati den bazei to 0? Kai allou ton eida na arxikopoiei se -1L... 
2) to megethos ths domhs mou tha eprepe na einai 53bye (3 pinakes *15 xarakthres o kathenas = 45 kai 4 bytes kathe akeraios (2*4=8)...45+8=53 alla to programma  mou gurna megethos 56!!. An afaireso tous 2 akeraious apo to telos ths domhs tha paro apotelesma 45 (3pinakes *15). An pali afaireso ton 1 akeraio tha paro apotelesma 52 eno tha eprepe na paro 45+4=49).. Auto pou me dokimes brhka einai oti an exo tous pinakes xarakthron kai toulaxiston 1 akeraio meta xrhsimopoiei 1 byte (gia kathe pinaka pou exo) epipleon...kapos san na tous diaxorizei..exei kaneis kamia idea giati ginete auto? 

sas paratheto ton kodika...
1000 euxaristo 
btw an kapoios kserei kanena ellhniko h kalo kseno newsgroup gia c h ellhniko forum gia c programming as mou pei plz..

#include <stdio.h>

struct ptisi{
                char ar_ptisis[15];    
                char poli_anax[15];  
                char poli_afix[15];     
                int ar_thesewn;   
                int kr_theseis;  
         
            }rec;     //record
           

main(){
    
    FILE *f;
    
    int sizerec;
    long lengthf;
    
    f=fopen("test.dat","w+"); 
    fwrite(&rec,sizeof(struct ptisi),1,f);
    fclose(f);
    
    
    f=fopen("test.dat", "r");
          
       if(f != NULL)
       {
             fseek(f, 0L, SEEK_END);
             lengthf = ftell(f);
             fclose(f);
       }
                  
           printf("to megethos tou arxeiou se bytes einai %d \n\n",lengthf);
        
       sizerec=sizeof(struct ptisi);          
       printf("h domh einai %d \n",sizerec);
       
       system("pause");
                  
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20040124/465044f8/attachment.htm>


More information about the Linux-greek-users mailing list