R
Raj
Following is a code to replace blanks in entered string with adequate
number of tabs & spacings as required. I've taken the width of tab as
5 characters here. The problem that occurs here is for the 2nd set of
blanks onwards, i.e. blanks after 2 words. For such blanks, the output
shows 1blank less than what has been entered in input. For 1st set of
blanks there is no problem, but for each successive set of blanks one
less blank is shown in output...
Code:
#include<stdio.h>
#define TABSTOP 5
main()
{
int c,i=0;
clrscr();
printf("Enter text\n");
while ((c=getchar())!='@') /* '@' signifies end of input */
if (c==' '){
while ((c=getchar())==' ')
i++;
if (i<TABSTOP){
while (i>=0){
printf(" ");
i--;
}
putchar(c);
continue;
}
if (i>=TABSTOP){
printf("\t");
i-=TABSTOP;
}
while (i>=0){
printf(" ");
i--;
}
}else
putchar(c);
getch();
return;
}
If anybody can help... thanks!
number of tabs & spacings as required. I've taken the width of tab as
5 characters here. The problem that occurs here is for the 2nd set of
blanks onwards, i.e. blanks after 2 words. For such blanks, the output
shows 1blank less than what has been entered in input. For 1st set of
blanks there is no problem, but for each successive set of blanks one
less blank is shown in output...
Code:
#include<stdio.h>
#define TABSTOP 5
main()
{
int c,i=0;
clrscr();
printf("Enter text\n");
while ((c=getchar())!='@') /* '@' signifies end of input */
if (c==' '){
while ((c=getchar())==' ')
i++;
if (i<TABSTOP){
while (i>=0){
printf(" ");
i--;
}
putchar(c);
continue;
}
if (i>=TABSTOP){
printf("\t");
i-=TABSTOP;
}
while (i>=0){
printf(" ");
i--;
}
}else
putchar(c);
getch();
return;
}
If anybody can help... thanks!