ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What kind of data do you expect on the screen and why do you expect it to look not like junk ? I.e. do you know what data is displayed on screen as something meaningful and what data as junk/gibberish ? If I may, have you ever heard of ASCII ? If not, try to perform web search on ASCII and/or try
man ascii
on your UNIX/Linux bix.
hi i m sorry, if had done any mistake. i actually meant to say that my output screen shows output in ascii data, then it holds for some seconds and prints something weird, which doesnt look like ascii. and then in the last it stops by saying segmentation fault.
so coz of that i said i am getting some junk data. the output i got is shown below.
Quote:
[root@is02vmbig code]# ./test4.out
value isð2ÀH,ü¿3n ð2ÀH,ü¿3nt,ü¿|,ü¿FKôo¨,ü¿H,ü¿ð+ü¿õmÔï
JÐSÔï
½
D t,ü¿ÐSl,ü¿¿0¿<¿Z¿e¿u¿¿ª¿½¿Ç¿þ¿¤þ¿*þ¿Âþ¿æþ¿÷þ¿*þ¿2þ¿=þ¿Jþ¿þ¿«þ¿Àþ¿Îþ¿ÿóëd
[-ü¿i686PuTTY./test4.outHOSTNAME=is02vmbig.ittiam.comTERM=xtermSHELL=/bin/bashHISTSIZE=1000SSH_CLIENT=::ffff:172.20.33.23 4410 22SSH_TTY=/dev/pts/1USER=rootLS_COLORS=no=00:fi=00:di=00;34:ln=00;36i=40;33:so=00;35:bd=40;33;01:cd=40;33;01r=01;05 ;37;41:mi=01;05;37;41:ex=00;32:*.cmd=00;32:*.exe=00;32:*.com=00;32:*.btm=00;32:*.bat=00;32:*.sh=00;3 2:*.csh=00;32:*.tar=00;31:*.tgz=00;31:*.arj=00;31:*.taz=00;31:*.lzh=00;31:*.zip=00;31:*.z=00;31:*.Z= 00;31:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.jpg=00;35:*.gif=00;35: *.bmp=00;35:*.xbm=00;35:*.xpm=00;35:*.png=00;35:*.tif=00;35:MAIL=/var/spool/mail/rootPATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/root/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le/bin:/root/mv_pro_4.0/montavista/pro/devkit/arm/v5t_le/armv5tl-montavista-linuxeabi/binINPUTRC=/etc/inputrcPWD=/win_d/WORKS/NEW_TOOL/TEST/codeLANG=en_US.UTF-8SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpassSHLVL=1HOME=/rootLOGNAME=rootSSH_CONNECTION=::ffff:172.20.33.23 4410 ::ffff:172.20.33.44 22LESSOPEN=|/usr/bin/lesspipe.sh %sG_BROKEN_FILENAMES=1_=./test4.outOLDPWD=/win_d/WORKS/NEW_TOOL/TEST./test4.outSegmentation fault
now i cant make out why is it showing this kind of output.
thanks.
my actual requirement is that, i have a bitstream of some 100mb. now i want to extract some 1000 bytes from it. well i dont know exactly how to perform this action so i tried to fread the file. but i still dont know how to extract some fixed number of data from binary file and display it in bits format.
hi i m sorry, if had done any mistake. i actually meant to say that my output screen shows output in ascii data, then it holds for some seconds and prints something weird, which doesnt look like ascii. and then in the last it stops by saying segmentation fault.
so coz of that i said i am getting some junk data. the output i got is shown below.
now i cant make out why is it showing this kind of output.
thanks.
As I have already asked, why do you expect a different output ? I.e. justify your expectations first.
my actual requirement is that, i have a bitstream of some 100mb. now i want to extract some 1000 bytes from it. well i dont know exactly how to perform this action so i tried to fread the file. but i still dont know how to extract some fixed number of data from binary file and display it in bits format.
Do any of you have any clue of how to apply this to read RAW disk content?
I'm doing some learning stage of ANSI C under linux and in my first attempt
I'd like
- read raw sectors form e.g /dev/sdb
- sequentially get one sector (so its 512 bytes) at a time
- print on the terminal the 512 bytes as ASCII characters (not formatted, just a raw output, ok, also formatted but it is not a must)
- at next sector, overwrite the precedent 512 characters (terminal should not scroll up)
- loop so fast until a user break happen
The majority of the question from the original poster (and you should have started your own thread, not hijack an existing and quite old one) has to do with the representation of his binary data. The problem is that ASCII doesn't define all 256 bytes as characters, and many of the one that it does define are not printable as human-readable glyphs.
Having said that, I suggest NOT reading partitions or block devices as a learning exercise. Read/write files, instead. When you print the contents, format it in human readable form, such as hex or octal text, with lines that break on friendly byte boundaries, etc. Example (untested)
Code:
for( i = 0; i < sizeof( myBuffer ); i++ ){
if( i % 16 == 0 ){
printf( "\n%08X: ", i );
}
printf( "%02X ", myBuffer[i] );
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.