| | |
Idea
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
till now i made this
C Syntax (Toggle Plain Text)
char *IntToarray(int num) { char *pch; int j; char temp[100]; if(num>0 || num<=19) pch=string[num]; if(num>=20 || num<=100) { if(num>=20 || num <=29) { j=num %10; strcpy(temp,string[20]); strcat(temp," "); strcat(temp,string[j]); puts(temp); } } }
Using your latest post, it still has the math error.
Still using your two arrays!
Using the single array
Still using your two arrays!
C Syntax (Toggle Plain Text)
char *IntToarray(int num) { char *pch; int j; char temp[100]; if(num>0 || num<=19) pch=string1[num]; else if(num>=20 || num<=100) { j=num %10; num = num / 10; strcpy(temp,string2[num]); if (j != 0) { strcat(temp,"-"); strcat(temp,string1[j]); } puts(temp); } }
Using the single array
C Syntax (Toggle Plain Text)
char *IntToarray(int num) { char *pch; int j; char temp[100]; if(num>0 || num<=19) pch=string[num]; else if(num>=20 || num<=100) { j=num %10; num = num / 10; strcpy(temp,string[num + 18]); if (j != 0) { strcat(temp,"-"); strcat(temp,string[j]); } puts(temp); } }
So with a little cleanup...
C Syntax (Toggle Plain Text)
char *IntToarray( char *szBuf, int num) { int j; if(num>0 || num<=19) strcpy( szBuf, string[num] ); else if(num>=20 || num<=100) { j=num %10; num = num / 10; strcpy( szBuf, string[num + 18]); if (j != 0) { strcat( szBuf, "-"); strcat( szBuf, string[j]); } } return szBuf; // return the passed in buffer! }
Missed a typo in your original. Zero was being ignored!
Also missed your || instead of &&
And only need to check for the upper range after the first test!
Also missed your || instead of &&
And only need to check for the upper range after the first test!
C Syntax (Toggle Plain Text)
char *IntToarray( char *szBuf, int num) { int j; *szBuf = 0; // Preset for error case! if (num>=0 && num<=19) strcpy( szBuf, string[num] ); else if( num<=100) { j=num %10; num = num / 10; strcpy( szBuf, string[num + 18]); if (j != 0) { strcat( szBuf, "-"); strcat( szBuf, string[j]); } } return szBuf; // return the passed in buffer! }
Last edited by wildgoose; Jun 26th, 2009 at 10:06 pm. Reason: code
okay i almost done it for but when i return it to char * it messed it up
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #define DEBUG char *string[]= { "zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen","fifteen", "sixten","sevten","eighteen","nineteen","twenty","thirty","fourty","fifty","sexty","seventy","eighty","nighty","hundreed" }; //from int to array and return char string /* n will be the index of the array like if its twenty thirty fourty etc*/ /*n2 will be the reminder*/ void ParseString(char *buffer1,char **buffer2,int n,int n2) { strcpy(buffer1,buffer2[n]); strcat(buffer1," "); strcat(buffer1,buffer2[n2]); } char *IntToarray(int num) { char *pch; int j; int z; char temp[100]; if(num>0 || num<=19) pch=string[num]; if(num==20 || num <100) { j=num % 10; num=( num /10) +18; if(j==0) return pch=string[num]; ParseString(temp,string,num,j); //puts(temp); this work i dunno why it get messed return pch=temp;//this doesnt work } } int main(void) { char *pch; pch=IntToarray(21); puts(pch); getchar(); return 0; }
i did till now but i got problem now now it when i get to like 111 or more i will get reminder 1 etc so it wont be from one hundered eleven it will be one hundered 1
anyways i will go sleep now i hope tommrow i will fix those errors.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #define DEBUG char *string[]= { "zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","tweleve","thirteen","fourteen","fifteen", "sixten","sevten","eighteen","nineteen","twenty","thirty","fourty","fifty","sexty","seventy","eighty","nighty","one hundreed", "two hundered","three hundered" }; //from int to array and return char string /* n will be the index of the array like if its twenty thirty fourty etc*/ /*n2 will be the reminder*/ #define LESSTHAN100 0 #define MORETHAN100 1 void ParseString(char *buffer1,char **buffer2,int n,int n2,int choice) { if(!choice) { strcpy(buffer1,buffer2[n]); strcat(buffer1," "); strcat(buffer1,buffer2[n2]); } else { strcat(buffer1,buffer2[n]); strcat(buffer1," "); strcat(buffer1,"and"); strcat(buffer1," "); strcat(buffer1,buffer2[n2]); } } char *IntToarray(int num) { char *pch; int j; int z; char temp[100]; if(num==0 || num<=19){ puts("we returned"); return pch=string[num]; } else if(num==20 || num <100) { j=num % 10; num=( num /10) +18; if(j==0) return pch=string[num]; ParseString(temp,string,num,j,LESSTHAN100); puts(temp); } else if(num==100 || num<=999) { j=num % 10; num= (num/10) +18; if(j==0) return pch=string[num]; ParseString(temp,string,num,j,MORETHAN100); puts(temp); } } int main(void) { char *pch; pch=IntToarray(41); //puts(pch); getchar(); return 0; }
![]() |
Similar Threads
- What is the best project idea! (Computer Science)
- Good Idea - Bad Brain! (Software Development Job Offers)
- I need an idea about my FYP (IT Professionals' Lounge)
- IDEA :: Make Notes in Internet Explorer (Web Browsers)
Other Threads in the C Forum
- Previous Thread: socket programming error
- Next Thread: help with output file from screen to csv file
Views: 1342 | Replies: 36
| Thread Tools | Search this Thread |
Tag cloud for C
#include * array arrays asterisks binarysearch calculate changingto char cm command copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv fflush file fork forloop framework functions getlasterror givemetehcodez grade graphics gtkwinlinux hacking hardware histogram homework inches include incrementoperators input iso kernel keyboard km lazy linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue mysql number opendocumentformat opensource overwrite owf pattern pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential socket socketprograming spoonfeeding standard string structures student systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi





