SHARE
TWEET

Untitled

a guest Apr 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <sstream>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. struct darray{
  9.     int * elemek;
  10.     int csize;
  11.     int mostani_elemszam;
  12. };
  13.  
  14. void alloc_elemek(darray& d, int max_size){
  15.  
  16.     cout<< "alloc d_array size"<<max_size<<endl;
  17.     d.csize= max_size;
  18.     d.elemek = (int*) malloc (sizeof(int)*d.csize);
  19.     d.mostani_elemszam=0;
  20. }
  21.  
  22. void realloc_elemek(darray& d, int max_size){
  23.     int * t=(int*) malloc (sizeof(int)*d.csize);
  24.     for (int iloop=0;iloop<d.mostani_elemszam;iloop++){
  25.         t[iloop]=d.elemek[iloop];
  26.  
  27.     }
  28.     int t_elemek=d.mostani_elemszam;
  29.     alloc_elemek(d,max_size);
  30.     for (int iloop=0;iloop<t_elemek;iloop++){
  31.         d.elemek[iloop]=t[iloop];
  32.  
  33.     }
  34. }
  35.  
  36.  
  37. void append(darray& d, int a ){
  38.     if (d.mostani_elemszam=d.csize){
  39.         realloc_elemek(d,d.mostani_elemszam*2);
  40.     }
  41.  
  42.     d.elemek[d.mostani_elemszam++]=a;
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49. void print_array(darray& d){
  50.     for (int iloop=0;iloop<d.mostani_elemszam;iloop++){
  51.         cout<<d.elemek[iloop]<<endl;
  52.  
  53.     }
  54. }
  55.  
  56. int main(){
  57.  
  58.  
  59. darray d;
  60.  
  61. alloc_elemek(d,1);
  62. append(d,2);
  63. append(d,78);
  64. print_array(d);
  65.  
  66.  
  67.  
  68.     ifstream myfile;
  69.     string tartalom1,tartalom2;
  70.     myfile.open("input.txt");
  71.     int szamlalo=0;
  72.  
  73.     stringstream ss;
  74.  
  75.  
  76.  
  77.     for (;getline(myfile,tartalom1);){
  78.         //cout<<tartalom1<<endl;
  79.             string b1,b2;
  80.         bool szeparator=false;
  81.         for (int iloop=0; iloop<tartalom1.size();iloop++){
  82.                 if (szeparator==''){
  83.                         int tmp= 0;
  84.                         ss>>tmp;
  85.                         append(d,tmp);
  86.                     continue;
  87.                 }
  88.  
  89.             }
  90.  
  91.     }
  92.     /*for (;;szamlalo++){
  93.         myfile>>tartalom1>>tartalom2;
  94.         cout<<tartalom1<<" "<<tartalom2<<endl;
  95.         if(szamlalo>1){
  96.             break;
  97.         }
  98.     }
  99. */
  100.    /* myfile>>tartalom1>>tartalom2;
  101.     cout<<tartalom1<<" "<<tartalom2<<endl;*/
  102.     //myfile.close();
  103.  
  104.     cout << "Hello world!" << endl;
  105.     return 0;
  106. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top