LINUX.ORG.RU

История изменений

Исправление LINUX-ORG-RU, (текущая версия) :

#include <stdio.h>
#include <string.h>
char * text =
"22:57:02 text 3821377\n"
"22:58:00 text 10121357\n"
"22:58:26 text 5621349\n"
"22:58:55 text 5921341\n"
"22:59:17 text 5021336\n"
"22:59:45 text 152221327\n"
"23:00:31 text 7721314\n"
"23:00:44 text 821310\n"
"23:01:10 text 3421299\n"
"23:01:16 text 3921296\n"
"23:01:16 text 1121297\n"
"23:02:37 text 6821284\n"
"23:02:38 text 2921283\n"
"23:03:09 text 7721281\n"
"23:03:17 text 1721280\n"
"23:03:19 text 2421278\n";


int main(int argc, char *argv[])
{
    long   lx = strlen(text);
    char * ls = text;
    char * le = text;
    for (int i = 0; i < lx; ++i)
    {
       if (*(text+i) == '\n')
       {
           ls = le;
           le = text+(i-5);
           while(ls!=le) { putchar(*ls++); };
           putchar(' ');le--;
           while(*le++!='\n'){putchar(*le); };
           le = text+(i+1);
       }
    }
    return 0;
}
dron@gnu:~$ gcc paste_space.c
dron@gnu:~$ bash -c "./a.out" #😱
22:57:02 text 38 21377
22:58:00 text 101 21357
22:58:26 text 56 21349
22:58:55 text 59 21341
22:59:17 text 50 21336
22:59:45 text 1522 21327
23:00:31 text 77 21314
23:00:44 text 8 21310
23:01:10 text 34 21299
23:01:16 text 39 21296
23:01:16 text 11 21297
23:02:37 text 68 21284
23:02:38 text 29 21283
23:03:09 text 77 21281
23:03:17 text 17 21280
23:03:19 text 24 21278

Исправление LINUX-ORG-RU, :

#include <stdio.h>
#include <string.h>
char * text =
"22:57:02 text 3821377\n"
"22:58:00 text 10121357\n"
"22:58:26 text 5621349\n"
"22:58:55 text 5921341\n"
"22:59:17 text 5021336\n"
"22:59:45 text 152221327\n"
"23:00:31 text 7721314\n"
"23:00:44 text 821310\n"
"23:01:10 text 3421299\n"
"23:01:16 text 3921296\n"
"23:01:16 text 1121297\n"
"23:02:37 text 6821284\n"
"23:02:38 text 2921283\n"
"23:03:09 text 7721281\n"
"23:03:17 text 1721280\n"
"23:03:19 text 2421278\n";


int main(int argc, char *argv[])
{
    long   lx = strlen(text);
    char * ls = text;
    char * le = text;
    for (int i = 0; i < lx; ++i)
    {
       if (*(text+i) == '\n')
       {
           ls = le;
           le = text+(i-5);
           while(ls!=le) { putchar(*ls++); };
           putchar(' ');le--;
           while(*le++!='\n'){putchar(*le); };
           le = text+(i+1);
       }
    }
    return 0;
}
dron@gnu:~$ gcc paste_space.c" 
dron@gnu:~$ bash -c "./a.out" #😱
22:57:02 text 38 21377
22:58:00 text 101 21357
22:58:26 text 56 21349
22:58:55 text 59 21341
22:59:17 text 50 21336
22:59:45 text 1522 21327
23:00:31 text 77 21314
23:00:44 text 8 21310
23:01:10 text 34 21299
23:01:16 text 39 21296
23:01:16 text 11 21297
23:02:37 text 68 21284
23:02:38 text 29 21283
23:03:09 text 77 21281
23:03:17 text 17 21280
23:03:19 text 24 21278

Исходная версия LINUX-ORG-RU, :

#include <stdio.h>
#include <string.h>
char * text =
"22:57:02 text 3821377\n"
"22:58:00 text 10121357\n"
"22:58:26 text 5621349\n"
"22:58:55 text 5921341\n"
"22:59:17 text 5021336\n"
"22:59:45 text 152221327\n"
"23:00:31 text 7721314\n"
"23:00:44 text 821310\n"
"23:01:10 text 3421299\n"
"23:01:16 text 3921296\n"
"23:01:16 text 1121297\n"
"23:02:37 text 6821284\n"
"23:02:38 text 2921283\n"
"23:03:09 text 7721281\n"
"23:03:17 text 1721280\n"
"23:03:19 text 2421278\n";


int main(int argc, char *argv[])
{
    long   lx = strlen(text);
    char * ls = text;
    char * le = text;
    for (int i = 0; i < lx; ++i)
    {
       if (*(text+i) == '\n')
       {
           ls = le;
           le = text+(i-5);
           while(ls!=le) { putchar(*ls++); };
           putchar(' ');le--;
           while(*le++!='\n'){putchar(*le); };
           le = text+(i+1);
       }
    }
    return 0;
}
dron@gnu:~$ bash -c "gcc paste_space.c" #😱
dron@gnu:~$ ./a.out 
22:57:02 text 38 21377
22:58:00 text 101 21357
22:58:26 text 56 21349
22:58:55 text 59 21341
22:59:17 text 50 21336
22:59:45 text 1522 21327
23:00:31 text 77 21314
23:00:44 text 8 21310
23:01:10 text 34 21299
23:01:16 text 39 21296
23:01:16 text 11 21297
23:02:37 text 68 21284
23:02:38 text 29 21283
23:03:09 text 77 21281
23:03:17 text 17 21280
23:03:19 text 24 21278