Advertisement
fabis_sparks

MaxStrLen_InFile

Jun 28th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string.h>
  5.  
  6. #define fileR argv[1]
  7. using namespace std;
  8. FILE *f;
  9. const int fw = 5;
  10.  
  11. int main(int argc, char* argv[])
  12. {
  13.     char q[5][255];
  14.     setlocale(LC_ALL, "Russian");
  15.     if (argc < 2) {
  16.         cout << "Недостаточно аргументов";
  17.         exit(1);
  18.     }
  19.     FILE *f = fopen(fileR, "r");
  20.     if (f == NULL) {
  21.         system("cls");
  22.         cout << "Файла не существует.\n\n"; // Вывести сообщение о успехе создания?
  23.         exit(1);
  24.     }
  25.     int i, j;
  26.     for (i = 0;i < fw;i++) fscanf(f, "%s", &q[i]);
  27.     fclose(f);
  28.     int maxlen = 0;
  29.     for (i = 0;i < 5;i++) {
  30.         cout << q[i] << endl;
  31.         if (strlen(q[i]) > maxlen) maxlen = strlen(q[i]);
  32.     }
  33.     cout << "Максимальная длина строки: " << maxlen << endl;
  34.     system("pause");
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement