can someone explain this exercise?

Started by
3 comments, last by White Crow 20 years, 8 months ago
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
~~~~~~I'll make you an offer you can't refuse...
Advertisement
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
-------------------------------------------http://www.thec.org
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?
Thanks. I think I understand it now, back to work
~~~~~~I'll make you an offer you can't refuse...
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 must get the value of n but<br></font><br>                   <font color=gray>// but how do I so? I mean putting the   <br></font><br>                   <font color=gray>// value of a variable into a string?<br></font><br><br><br>			<br>		}<br>	}<br>	<br>	<font color=blue>if</font>(c==''\n'')<br>	{<br>		r[<font color=purple>i</font>] =c;<br>		++i;<br>	}<br><br>	r[<font color=purple>i</font>] =''\0'';<br><br>	<br>}<br><br></pre><!–ENDSCRIPT–><br><br>   
~~~~~~I'll make you an offer you can't refuse...

This topic is closed to new replies.

Advertisement