LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-01-2008, 12:34 PM   #1
RudraB
Member
 
Registered: Mar 2007
Distribution: Fedora
Posts: 264

Rep: Reputation: 23
irritating character in output


hello friends,
in a code i am trying to retrive the machine bit the code. The code
is:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
main(){
FILE *stream;
char sys[8],*sysptr;
int bit;
sysptr = &sys[0];
sys[6] = 0x0;
stream=popen("file /sbin/init|awk '{print $3}'|cut -c0-2","r");
fread(sysptr,1,2,stream);
pclose(stream);
printf("bit=%s",sysptr);
}
and the output is

Quote:
bit=32�
why the irritating symbol after 32 is coming? can you suggest me
something?
 
Old 08-01-2008, 12:53 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Well, counting for cut starts at one, so cut -c0-2 is an error. Change it to -c1-2.

Your problem is that you are not properly initiating the buffer sys. You are setting the seventh element to zero but the string you are reading is less than 7 characters long, so there is garbage in the buffer.

Replace your sys[6]=0x0 with memset(sys,0x0,8) and it will work.
 
Old 08-01-2008, 01:12 PM   #3
RudraB
Member
 
Registered: Mar 2007
Distribution: Fedora
Posts: 264

Original Poster
Rep: Reputation: 23
thnx jiml8,
its just what i was looking for!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to output a single character several times? daYz Programming 5 09-15-2006 01:24 PM
What is the ninth (9th) character or field in the output string of rpm -V ? zimon Linux - Distributions 1 08-28-2006 02:47 PM
irritating ubuntu ololad8 Linux - Software 15 07-13-2006 01:47 AM
about wide character and multiple byte character George2 Programming 5 05-23-2006 01:03 AM
Irritating Sound Problem ArthurDent Linux - Newbie 20 06-30-2004 08:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration