This commit is contained in:
NaiJi ✨ 2024-05-02 14:54:04 +04:00
parent 1c56e1c7e3
commit 86db643a2e
1 changed files with 72 additions and 0 deletions

View File

@ -0,0 +1,72 @@
#include <stdio.h>
int _getline(char s[], int lim)
{
int c, i, j;
for (i = 0; (c = getchar()) != '\n'; ++i)
{
if (i < lim - 1)
s[i] = c;
}
j = i;
if (j > lim - 1)
j = lim - 1;
s[j] = '\0';
return j - 1;
}
void entab(char to[], char from[], int columns)
{
int is_placing_spaces = 0;
int remaining_spaces = columns;
int i_to = 0;
int i_from = 0;
while (from[i_from] != '\0')
{
if (from[i_from] == '\t')
is_placing_spaces = 1;
if (is_placing_spaces)
{
if (remaining_spaces == 0)
{
is_placing_spaces = 0;
remaining_spaces = columns + 1;
++i_from;
}
else
{
to[i_to] = '_';
++i_to;
}
}
else
{
if (remaining_spaces == 0)
remaining_spaces = columns;
to[i_to] = from[i_from];
++i_to;
++i_from;
}
--remaining_spaces;
}
to[i_to] = '\0';
}
main()
{
int size = 500;
char from[size];
char to[size];
while (1)
{
_getline(from, size);
entab(to, from, 4);
printf("%s\n", to);
}
}