-   Linux - Newbie (
-   -   A problem with tabs (

rmknox 04-30-2011 03:28 PM

A problem with tabs

I've written a c program which uses tab characters in the output. Output goes to stdout.

When I run it at the terminal command line - output is tabbbed.

If I direct output to a file (./program > book.txt) , and use "more" to display the file, output is tabbed.

If I send the file to my HP 1020 printer, output is not tabbed. I get a space at the location of each tab character.

If I try to open the file with gedit, gedit refuses to open it and says that it has not been able to detect the character encoding. I try all the obvious choices and it rejects them all.

If I try to open it with notepad, notepad opens it and shows the output as tabbed.

If I display it with od, I see the hex 09 characters in the file.

1) what is happening and why?

2) as I recall there is a utility that lets me change the attributres of a file. I imagine I can correct the encoding, but I dont remember what utility.

3) is there sometihng that i need to do as regards compiler settings to get the file marked correctly?

penguiniator 04-30-2011 05:54 PM

The expand utility will convert tabs to spaces. That may solve the problem with your printer. How Gedit interprets your file encoding depends on what else it contains. Perhaps a better editor will work around the problem. Have you tried opening it in Vim?

rmknox 04-30-2011 08:44 PM

thanks - expand replaced the tab characters with spaces

archtoad6 05-05-2011 03:30 PM

FWIW, pr is more complex & therefore more flexible; & of course harder to use.

W/ the right options it can convert spaces back to tabs. Piped into itself (w/ the right options) it can convert n spaces to tabs, & then the tabs to m spaces.

It does not have:

-t, --tabs=LIST
use comma separated list of explicit tab positions

Post 4500, 1.88 ppd

All times are GMT -5. The time now is 05:51 PM.