SHARE
TWEET

Untitled

a guest Dec 10th, 2018 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //b2v.c :: binary-file to vector. 6.12.18
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. #include "kfst.h"
  6.  
  7. int main(){
  8.     FILE *inpf=NULL;
  9.    
  10.     int i,j,n,mn,mx,m,svp;
  11.     struct kfst *r;
  12.     struct kfst **v;
  13.     struct kfst **sv;        
  14.     inpf=fopen("kfst.vec","rb");
  15.     if(inpf==NULL){
  16.        printf("ei saa avada kfst.vec\n");
  17.        return 4;
  18.        }
  19.     fscanf(inpf,"%d",&n);
  20.     printf("n=%d\n",n);
  21.     v=malloc(n*sizeof(struct kfst *));
  22.     for(i=0;i<n;i++){
  23.        r=malloc(sizeof(struct kfst));
  24.        fread(r,sizeof(struct kfst),1,inpf);
  25.        v[i]=r;
  26.        }
  27.     for(i=0;i<n;i++){
  28.       r=v[i];
  29.       printf("%s %s %d %s %s\n",r->enimi,r->pnimi,r->matr,r->kood,r->meil);  
  30.       }
  31.     fclose(inpf);
  32. //--------------------------------------------
  33. //teen sagedusvektori (v6ti on matr) ja kirjutan kettale
  34. //faili kfst.sv: 1. rida m=sv-elementide arv ja svp:
  35. //sv pikkus baitides, 2.rida: sv, edasi kirjed.
  36. //s-sagedusvektor,m*sizeof(int)-sagedusvektori pikkus
  37. //int *sagedused(void)
  38. //{
  39. //    int i,j,b;
  40.     int b;
  41.     int *s;
  42.     mn=mx=v[0]->matr;
  43.     for(i=1;i<n;i++){
  44.        if(v[i]->matr < mn)mn = v[i]->matr;
  45.        else if(v[i]->matr > mx)mx = v[i]->matr;
  46.        }
  47.     printf("mn=%d mx=%d\n",mn,mx);
  48.     m=((mx-mn)+1)*4;
  49.     s=malloc(m*sizeof(int));
  50.     memset(s,'\0',m*sizeof(int));
  51.     for(i=0;i<n;i++)s[v[i]->matr - mn]=1;
  52. //    printf("sagedusvektor:\n");
  53. //    for(j=0;j<m;j++)printf("%d ",s[j]);
  54. //    printf("\n");
  55.     j=0;
  56.     for(i=0;i<m;i++){
  57.        if(b=s[i]){
  58.           for(;b;b--){
  59.              v[j]->matr=i+mn;
  60.              j++;
  61.              }
  62.           }
  63.        }
  64. //    return(s);
  65. //}  
  66.  
  67.     int sisestus;
  68. //    printf("Sisesta matriklinumber: ");
  69. //    scanf("%d", &sisestus);
  70.     printf("%d", s[178441]);
  71.  
  72.  
  73.  
  74.     system("pause");
  75.  
  76. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top