C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 8th, 2003, 02:11 PM
gtpc gtpc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 228 gtpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
packing an int with 8 single digits in bit-form, output odd when i initialized

I find this bit of code acting weird. I hope I am not
missing something obvious, but, here is what is
happening. When I remove the line:

int i;

and compile, it prints out a bit representation of all
8 single digits. When I put it in (because I wanted
to add code for unpacking the digit string) I get a seg fault.

The code seems simple enough...
PHP Code:
 int main(void)
{
// int i;
char *s;

printf("Input 8 decimal digits: \n");
scanf("%s"s);
bit_print(convert(s));
// in here I was going to call a function for 
// unpacking the int, to its original string
putchar('\n');
return 
0;

I should also mention that when I
compiled this with my other functions (which I
will attach) in DOS, they really screwed up.
Instead of packing the int efficiently, it would
default to the ERROR message at the end of the
pack_bit() funtion. In Xandros, they compile and
work great, as long as, like I said, I hash-out the
'int i' part.
Any ideas what I am doing wrong? I will supply
my other funtions if you think it would help...
TIA
Attached Files
File Type: txt 7_7.txt (1.2 KB, 370 views)

Last edited by gtpc : November 8th, 2003 at 02:18 PM.

Reply With Quote
  #2  
Old November 8th, 2003, 07:28 PM
mitakeet's Avatar
mitakeet mitakeet is offline
I'm Baaaaaaack!
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Jul 2003
Location: Maryland
Posts: 5,538 mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level)mitakeet User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 2 h 38 m 46 sec
Reputation Power: 242
You aint got no memory allocated for s! You are lucky that it ever run, you are surely poluting some memory somewhere. Either statically allocate memory (easiest) or dynamically allocate (remember to free!) before you try to do input on it.
__________________

My blog, The Fount of Useless Information http://sol-biotech.com/wordpress/
Free code: http://sol-biotech.com/code/.
Secure Programming: http://sol-biotech.com/code/SecProgFAQ.html.
Performance Programming: http://sol-biotech.com/code/PerformanceProgramming.html.
LinkedIn Profile: http://www.linkedin.com/in/keithoxenrider

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Me, I just made it up

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw

Reply With Quote
  #3  
Old November 9th, 2003, 08:30 AM
gtpc gtpc is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canada
Posts: 228 gtpc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
I knew it had to be some simple oversight! Oh well. Thanks a bunch, and it of course works perfectly immediately. Onward and upward! Thankyou for your attention Mitakeet... what is mitakeet anyways?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > packing an int with 8 single digits in bit-form, output odd when i initialized

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap