Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <windows.h>
- using namespace std;
- struct fridge{
- char country[20];
- char model[20];
- char quantity[20];
- };
- void print (const fridge &a)
- {
- cout<<a.country<<", "<<a.model<<", "<<a.quantity<<endl;
- }
- int search (fridge a[], char x[], int size, int beg)
- {
- for (int i=beg; i<size; i++)
- {
- if (strncmp(a[i].model, x, 4)==0) return i;
- }
- return size+1;
- }
- main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int size = 4;
- fridge a[size] = {{"russian","2018samsung", "40"}, {"german","2016Bosh", "25"}, {"japan","2017sharp", "10"}, {"french","2016LG","3"}};
- for (int i = 0; i<size;i++) print(a[i]);
- char oldest[5];
- strncpy(oldest,a[0].model,4);
- for (int i = 0; i < size; i++) {
- if(strncmp(oldest,a[i].model,4)>0) strncpy(oldest,a[i].model,4);
- }
- cout << "search:\n";
- for(int y = search(a, oldest,size,0); y<size; y = search(a, oldest,size,y+1)) {
- print (a[y]);
- }
- }
Add Comment
Please, Sign In to add comment