Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <string.h>
  5. using namespace std;
  6.  
  7. const char fileData[] = "Duomenys.txt";
  8. const char fileResult[] = "Rezultatai.txt";
  9.  
  10. void read(const char fileData[], string &carFind, string carMap[], string model[], int &n)
  11. {
  12.     ifstream in(fileData);
  13.     char ch[30];
  14.     char chh[30];
  15.     string temp;
  16.     in.get(ch, 11);
  17.     carFind = ch;
  18.     in >> n;
  19.  
  20.     if (carFind.length() <= 10)
  21.     {
  22.         for (int i = 0; i < n; i++)
  23.         {
  24.             in.ignore();
  25.             in.get(ch, 11);
  26.             carMap[i] = ch;
  27.             in.get(chh, 26);
  28.             model[i] = chh;
  29.             if (model[i].length() > 25)
  30.             {
  31.                 cout << "Ivedete per daug simboliu! " << i + 1 << " eiluteje.";
  32.             }
  33.         }
  34.     }
  35.     else
  36.     {
  37.         cout << "Per ilgas ivestas modelis";
  38.     }
  39.     in.close();
  40. }
  41. void print(const char fileOutput[], string carFind, string carMap[], string model[], int n)
  42. {
  43.     ofstream out(fileOutput);
  44.     for (int i = 0; i < n; i++)
  45.     {
  46.         if (carFind == carMap[i])
  47.         {
  48.             out << carMap[i] << model[i] << endl;
  49.         }
  50.     }
  51. }
  52. int main()
  53. {
  54.     int n;
  55.     string carFind, carMap[30], model[30];
  56.     read(fileData, carFind, carMap, model, n);
  57.     print(fileResult, carFind, carMap, model, n);
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement