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 January 1st, 2013, 08:57 AM
freemind21 freemind21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 freemind21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
Cool Need Some Help! Rookie :)

Hello i have this program and i need some help to fix it,
i think the problem is on command " puts(name[digit + 20 ]) "
it is working fine until 109 but after this something is wrong
this the program:
/*count.c*/
int putchar(int value);
int puts(const char *string);

char *name[] = {
"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen",
"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety", "one hundred", "one thousand" ,
};

char *itoa10(unsigned long num)
{
static char buf[12];
int i;
buf[10] = 0;
for (i = 9; i >= 0; --i)
{
buf[i] = (char)((num % 10) + '0');
num /= 10;
}
return buf;
}

void number_text(unsigned long number)
{
int digit;
puts(itoa10(number));
puts(": ");

if(number >= 20)
{
digit = number / 10;
puts(name[digit + 20 ]);
putchar(' ');
number %= 10;
}


puts(name[number]);
putchar ('\r');
putchar ('\n');
}


int main()
{
unsigned long number=0, i=0;
int am;
number = 80;
am=1143;
for(i = 80; i <= am ; i++)
{
number_text(number);
number ++;
// number *= 3;
//++number;
}
system ("pause");
}

any help will be good! thanks

Reply With Quote
  #2  
Old January 1st, 2013, 10:45 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
Trouble occurs well before the segfault.

0000000109
:
one hundred
nine

0000000110
:
one thousand


Were this my project I would start with a sound program that could write numbers through 99.

Next I'd extend it to write all the numbers from 1 to 999, keeping "one" separate from "hundred" whereas you have a "one hundred" string.

3rdly, I'd enable groups of thousands incorporating "thousand", "million", "billion". These would call on the write1to999 function to work with integers mod 1000.

Fourthly, depending on if you started from the most significant group or the least significant you may need to rearrange the groups to print them in the correct order.

>>> import WriteNumber
>>> WriteNumber.WriteNumber(0)
'zero'
>>> WriteNumber.WriteNumber(-23421882342342882238828832987243987)
'negative twenty-three decillion four hundred twenty-one nonillion eight hundred eighty-two octillion three hundred forty-two septillion three hundred forty-two sextillion eight hundred eighty-two quintillion two hundred thirty-eight quadrillion eight hundred twenty-eight trillion eight hundred thirty-two billion nine hundred eighty-seven million two hundred forty-three thousand nine hundred eighty-seven'
>>>
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 1st, 2013, 12:38 PM
freemind21 freemind21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 freemind21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 m 5 sec
Reputation Power: 0
re:

the thing is that the only solution i can apply is had to be only by modify the current program..

Reply With Quote
  #4  
Old January 1st, 2013, 12:50 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,350 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 7 h 38 m 45 sec
Reputation Power: 383
Retain

int main()
{


That part is good.
Comments on this post
dwise1_aol disagrees: Yet he does not return a value. That part is bad.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Need Some Help! Rookie :)

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