Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #pragma  warning(disable: 4996)
  4. #include <malloc.h>
  5. int StringTreatment(void)
  6. {
  7.     int s=0, k=0;
  8.     char b;
  9.     char *arr;
  10.     arr = (char *)malloc(sizeof(char));
  11.         do
  12.         {
  13.             arr[s] = (char) getc(stdin);
  14.             if ((arr[s]!='\n') && (arr[s]!=EOF)) printf("%c", arr[s]);
  15.             if (!isspace((int)arr[s]) == 0) k++;
  16.             s++;
  17.             arr = realloc(arr, (s+1)*sizeof(char));
  18.             if (arr == NULL)
  19.             {
  20.                 printf("ERROR: realloc doesn't work. \n");
  21.                 return -1;
  22.             }
  23.             b = arr[s-1];
  24.         }
  25.         while ((b!='\n') && (b!=EOF));
  26.         if ((arr[0]!=EOF) && ((arr[0]!='/') && (arr[1]!='/')) && (k!=s)) printf(" == ERROR: Still can't understand that's the string about. \n");
  27.         if (((arr[0]=='/') && (arr[1]=='/')) || (k==s)) printf("\n");
  28.         return 0;
  29. }
  30. int main(int argc, char const* argv[])
  31. {
  32.     FILE *f;
  33.     if (argc>2) {
  34.         printf("ERROR: Too much arguments. \n"); /*обрабатываем случай с бОльшим количеством аргументов*/
  35.         return -1;
  36.     }
  37.     else {
  38.         if (argc==2)
  39.         {
  40.             f = freopen(argv[1], "r", stdin);    /*открываем файл в поток*/
  41.             if (f == NULL) {
  42.                 printf("ERROR: File do not exist. \n"); /*обрабатываем случай, когда файл не удалось открыть*/
  43.                 return -1;
  44.             }
  45.         }
  46.         do {
  47.             StringTreatment();
  48.             if (stdout == NULL)
  49.             {
  50.                 printf("ERROR: cannot read the string. \n");
  51.             }
  52.         }while (feof(stdin) == 0);
  53.     }
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement