Originally Posted by
memcpy
Nice job, but you can get rid of a few more things:
- kelime1 is only used for onluk[sayi/10-1], so why make an entirely new variable?
- keime2, rakam, and number are unused variables
- no idea what the getche() at the end does..
Also, not really necessary, but because the "ty" is repeated across onluk, and the "teen" across onyirmi, it could be manually added in the printf later and not allocated in the variable.
yes you are right , but this is a part of main program, which is read file and if you see 0-99 numbers , write ont file as the name of number and save.
after i will use this function to find number and replace the word.
that kelimemain will be the replaced word, and i am dealing with other codes to combine with them with this code.
Code:
#include <stdio.h>
char kelimemain[14];
int main()
{
int number;
char rakam[14];
char *birlik[]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char *onluk[]={"ten","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety"};
char *onyirmi[]={"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int sayi=0,i,r;
int length=0,length1=0;
char *kelime1;
char *kelime2;
char *kelime3;
printf("Please enter a number [0-99]:");
scanf("%d",&sayi);
printf("\n");
if((sayi<10)&&(sayi>=-1))
{
kelime1=birlik[sayi];
printf("-%s-",kelime1);
}
if(((sayi<100)&&(sayi>19))&&(sayi%10!=0))
{
kelime1=onluk[(sayi-sayi%10)/10-1];
kelime2=birlik[sayi%10];
//printf("-%s%s-",kelime1,kelime2);
}
if((sayi%10==0)&&(sayi!=0))
{
kelime1=onluk[sayi/10-1];
//printf("-%s-",kelime1);
}
if((sayi<20)&&(sayi>10))
{
kelime1=onyirmi[sayi%10-1];
//printf("-%s-",onyirmi[sayi%10-1]);
}
for(i=0;kelime1[i]!='\0';i++) length++;
length1=length;
//printf("%d\n",length);
for(i=0;kelime2[i]!='\0';i++) length++;
//printf("%d\n",length);
for(i=0;i<length1+1;i++) kelimemain[i]=kelime1[i];
r=0;
for(i=length1;i<length+1;i++,r++) kelimemain[i]=kelime2[r];
//printf("%d",length);
printf("\nzz--%s--zz",kelimemain);
return length;
}
some compilers are ,when you press f5 execute, it appears and otomaticly close the program.so i put getche(); to see what is there on the screen.
rakam and others not important , i usually delete and fix the warnings after my program works perfectly.