Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <ctype.h>
- #pragma warning(disable: 4996)
- #include <malloc.h>
- int StringTreatment(void)
- {
- int s=0, k=0;
- char b;
- char *arr;
- arr = (char *)malloc(sizeof(char));
- do
- {
- arr[s] = (char) getc(stdin);
- if ((arr[s]!='\n') && (arr[s]!=EOF)) printf("%c", arr[s]);
- if (!isspace((int)arr[s]) == 0) k++;
- s++;
- arr = realloc(arr, (s+1)*sizeof(char));
- if (arr == NULL)
- {
- printf("ERROR: realloc doesn't work. \n");
- return -1;
- }
- b = arr[s-1];
- }
- while ((b!='\n') && (b!=EOF));
- if ((arr[0]!=EOF) && ((arr[0]!='/') && (arr[1]!='/')) && (k!=s)) printf(" == ERROR: Still can't understand that's the string about. \n");
- if (((arr[0]=='/') && (arr[1]=='/')) || (k==s)) printf("\n");
- return 0;
- }
- int main(int argc, char const* argv[])
- {
- FILE *f;
- if (argc>2) {
- printf("ERROR: Too much arguments. \n"); /*обрабатываем случай с бОльшим количеством аргументов*/
- return -1;
- }
- else {
- if (argc==2)
- {
- f = freopen(argv[1], "r", stdin); /*открываем файл в поток*/
- if (f == NULL) {
- printf("ERROR: File do not exist. \n"); /*обрабатываем случай, когда файл не удалось открыть*/
- return -1;
- }
- }
- do {
- StringTreatment();
- if (stdout == NULL)
- {
- printf("ERROR: cannot read the string. \n");
- }
- }while (feof(stdin) == 0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement