Archived

This topic is now archived and is closed to further replies.

White Crow

can someone explain this exercise?

Recommended Posts

White Crow    122
Hi I am stuck on an exercise because english is not my best language, this is the exercise: Write a program that replaces tabs in its input with the proper number of blanks to space to the next tab stop. Do they mean that every time TAB is pressed, let''s say the number 3 is has to be outputted to the screen or that if you press TAB multiple times a variable keeps incrementing until you press another key and then the variable is outputted to the screen? Thanks in advance Whitecrow

Share this post


Link to post
Share on other sites
thec    212
Naa, it just means you should replace tab characters (was it ascii sign 9?) with, say, 4 spaces (ascii sign 32) ... this is done in some areas because some output windows doesn''t know how to handle tabs... or such

Albert

Share this post


Link to post
Share on other sites
jammyt    122
As thec said it might be replace each tab with 4 spaces but more likely I think it is the following as the question is to the next tab stop:

In a word document or something similar you have tab stops at positions such as:
0 4 8 12

You could type ''cheers'' then hit . You would not expect the program to produce 4 spaces but in this case 2 to take you to the next tab stop at position 8.

Example of typing in cheersmate (. denoutes space)
0 4 8 12
Cheers..mate

Does that make sense?

Share this post


Link to post
Share on other sites
White Crow    122
I had a function that reads input from the keyboard into an array but I have a problem with it now, but first the code



void getinput (char r[], int limit) // read input into r.

{
int i , c, , n = 4;

for(i=0; i<limit && (c=getchar()) != EOF && c!=''\n''; ++i)
{
if (c!= ''\t'')
{
r[i] = c;
--n;

if (n=0)
n=4;
}

else
{
// here r[i] must get the value of n but

// but how do I so? I mean putting the

// value of a variable into a string?




}
}

if(c==''\n'')
{
r[i] =c;
++i;
}

r[i] =''\0'';


}



Share this post


Link to post
Share on other sites