0
C Programming Language AINSI Book Excercise 1-20
Excercise :Write a program detab that replaces tabs in the input with the proper number of blanks to space to the next tab stop. My Question: The program does seem working when the input is a or ab, or abc etc. But I'd like to know the reason why it doesn't work when the input is a\tab\t and also if there is a major bug or error in terms of my code. Note: \t is used as a represantation of the Tab button in terms of the input written. The Code: https://code.sololearn.com/c1zp48UIsbYx/#c
17 Respostas
+ 2
mert aydın I think you need to use a else if in line 28, that's all. Otherwise the program will print the tab character and increment position instead of continuing the loop.
+ 2
mert aydın
Did you run that code?
How you are giving input...
I think its about, tab button, not \t escape character.
+ 2
~ swim ~
Is this for
A tab key from keyboard press or for manually entering \t \tab?
+ 2
~ swim ~
But he is looking for from keyboard.
I think it should work but from this app am not able to enter tab, it just input console disappearing, when trying to enter. How to do it?
He given a link above one. He made according that.. He said that working properly in other compiler, then why not working this..
If i copy tab, and pasted it in console then it is reading as a space only..
So he wants tab reading from keyboard..
+ 2
~ swim ~
Yes. First I replayed same later he added note there.
I asked, is it working in other compilers.. He replayed yes..Also about Link example, he tested in PC, while it is working then why not his program not working.. Why not able to read a tab?.. doubt..!
It should work.. But Only how to input tab?
+ 2
looks like Sololearn will be archive for exercises soon 🤣
+ 1
Because from the input \t is equal to 2 characters not a space..
I
You are reading character by character so first c=\ is compared next c=t is compared but not as \t...
+ 1
Edit: I guess you mean \t literally. I tried to use it as a representation of Tab button in terms of the input.
Jayakrishna Then with the same logic the program in the below shouldn't be working. I did understand your point but it doesn't make sense for me. As far as I know escape characters are recognized as one character. Thanks for your answer anyway. If you can explain and eloborate more on this point I'll be thankful.
http://www.learntosolveit.com/cprogramming/Ex_1.20_detab.html
+ 1
Jayakrishna
Yes I did and it's working well though I didn't understand the part : nb = TABINC - (( pos - 1) % TABINC);
( For example when the position is 2 the nb should be 2 -1 = 1 and 1 % 8 = 0 and 8 - 8 = 0)
I've edited my answer yes it is about the tab button. My bad. I've tried to use \t as a reprensentation of Tab button in terms of input.
Note: The input is given by (( c = getchar()) != EOF) this part of the code
+ 1
mert aydın
Ok. I just seen now,.
Is that formula part only you are searching for answer?
And 1%8=1 not 0
+ 1
Jayakrishna Oh I've got my answer for that part thanks to you. I confused it with the arithmetic operator /. Actually I search for an answer for my code in the main question. I've shared my code in the code playground and also shared the link in the post.
+ 1
Aaron Eberhardt Question is solved thanks to you. It's working thanks a lot. I'd like to also thank to people who tried to help me to solve this question and put effort in it.
0
mert aydın
Ok. Thats fine you got your answer.
Your Wel come...
0
Jayakrishna
Thank you for your help but can you answer the main question in the first post. I've written it for the same purpose with the code I've refered. My code is in the below.
The Code: https://code.sololearn.com/c1zp48UIsbYx/#c
0
you are taking c as intiger. So converted to ascii value. And tab acsii 9, is defferent to space 32...
0
Jayakrishna I didn't get you. Because the excercise says determine a tabstop. Let's say the tabsop is 6 and user enters a\t then a11111 is the output. If ab is entered then ab1111 should be the output.
0
OK. I got it.. But in keypad tab button not working properly in my mobile... It should work I guess..