#include <stdio.h>
main()
{
int len;
int position1 = 0; int position2 = 0;
char line[1000];
char output[20];
while( (len = getline(line, 1000)) > 0 )
{
while(position1 < 20 && line[position2] != '\n')
{
output[position1] = line[position2];
++position1; ++position2;
}
if(line[position2] == '\n')
{
output[position1] = '\n';
printf("%s\n", output);
position1 = 0;
}
if(line[position2] == ' ')
{
printf("%s\n", output);
++position2;
position1 = 0;
}
else if(line[position2-1] == ' ')
{
output[19] = '\0';
printf("%s\n", output);
position1 = 0;
}
else if(line[position2-2] == ' ')
{
output[18] = '\0';
printf("%s\n", output);
--position2;
position1 = 0;
}
else if(line[position2] != ' ' && line[position2-1] != ' ' && line[position2-2] != ' ')
{
output[19] = '-';
--position2;
printf("%s\n", output);
position1 = 0;
}
}
}
int getline(char s[],int lim)
{
int c, i;
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n')
{
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
논리 자체는 일단 비슷하게 접근하고 있는거 같긴한데..아예 출력이 안되네요 어디가 잘못된걸까요..