Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a tab in a text file?

Tags:

c++

c

file-io

Is detecting tabs same as detecting the spaces? i.e. for detecting a space, I would just compare the space character with its ascii number.

For a tab do I have to search for '\t' character in the file or there is some other way?

like image 270
Aquarius_Girl Avatar asked Jun 09 '11 06:06

Aquarius_Girl


2 Answers

if('\t' == myChar)

This would work, and would be better than checking against 9 since 9 may not be a guaranteed value across all architectures.

like image 90
Yew Long Avatar answered Oct 08 '22 14:10

Yew Long


Assuming you are working with ASCII data, you can just search for a byte with value '\t' (9) in the text file. Tabs are represented as a single byte in text files and most libraries for reading files don't do anything special with those bytes.

like image 44
David Grayson Avatar answered Oct 08 '22 15:10

David Grayson