mjspdr 님이 쓰신 글 :
: 안녕하세요. C언어 초보인데요.
: 지금 한 라인에서 tab을 찾으면 그 탭을 빈칸으로 바꾸는 프로그램 짜는데요.
: 탭 하나는 되는데 그 다음에 탭이 연속해서 나올 경우 제대로 돌지 않네요.
: 소스는 다음과 같습니다. 보시고 조언 좀 부탁드려요.
: #include <stdio.h>
: #include <string.h>
: #define MAXLINE 100
:
: void dtab(char it[], char ot[],int x);
: int main()
: {
: int i,c;
: char input[MAXLINE];
: char output[MAXLINE];
: int len;
: len=0;
: i=0;
: while((c=getchar())!='\n')
: {
: input[i++]=c;
: len=i;
: }
: dtab(input,output,len);
:
: return 0;
: }
: void dtab(char it[],char ot[],int x)
: {
: int i,j,k,t;
: for(i=0;i<x;i++)
: {
: ot[i]=it[i];
: if(it[i]=='\t')
: {
: for(j=x+5,k=x;j>=i;j--,k--)
: {
: ot[j]=it[k];
: if(j<=i+5)
: {
: ot[j--]=' ';
: }
: }
: }
: }
: printf("%d",strlen(ot));
: for(t=0;t<x+5;t++)
: {
: printf("%c",ot[t]);
: }
: }
void dtab(char it[],char ot[],int x)
{
int i,j,oi=0;
for(i=0;i<x;i++)
{
if(it[i]=='\t')
{
for(j=0;j<5;j++)
{
ot[oi++]=' ';
}
}
else
{
ot[oi++]=it[i];
}
} /*end of for(i=0;i<x;i++)*/
ot[oi] = '\0'; /*널 종료 문자*/
printf("%d\n%s",strlen(ot),ot);
}
|