This commit is contained in:
NaiJi ✨ 2024-05-02 15:15:30 +04:00
parent 86db643a2e
commit de32013d6c
1 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,59 @@
#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 spaces_counter = 0;
int from_i = 0;
int to_i = 0;
while (from[from_i] != '\0')
{
++spaces_counter;
++from_i;
if (spaces_counter == columns)
{
to[to_i] = '\t';
++to_i;
spaces_counter = 0;
}
}
while (spaces_counter > 0)
{
to[to_i] = '_';
++to_i;
--spaces_counter;
}
to[to_i] = '\0';
}
main()
{
int size = 500;
char from[size];
char to[size];
while (1)
{
_getline(from, size);
entab(to, from, 4);
printf("%s\n", to);
}
}