• C

Printing Error.....


Hi,
I've written some code for converting numbers to equivalent
words in C.(1=One, 501= FiveHundred And One......)

The Output I'm storing in a char*. Most of the times the
output is correct as expected. But for few numbers say
5001,2040,3015(No digits in hudredth, tenth place sometimes)
the Output is only fiveThousand,twoThousand,Threethousand
respectively.

While debugging I found just before printing the Output
variable has the desired string. I tried using both
printf,puts
Can anyone say why it is not printing properly?

Regards,
Premadhas
premadhasAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rbrCommented:
Can you pls post the code. For printing a string use

printf ("%s",varname);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
How are you storing in a char*?
How did you find just before printing the Output variable has the desired string?
0
premadhasAuthor Commented:
Clarifications Ozo.....
1. I've stored using strcpy and strcat
2. I checked using watch

Sorry rbr  I tried printf before...
0
MSSPs - Are you paying too much?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

rbrCommented:
Pls post your code!
0
premadhasAuthor Commented:
main()
{
      int digit_array[50], number;
      char* TempOut;

      printf("Enter a number between 0-9999");
      scanf("%d", &number);

      digits = split(digit_array, number);

      switch(digits)
      {
      case      1:
            check_unitplace(digit_array, number);
            break;

      case      2:
            check_tenplace(digit_array, number);
            if(PathSelect_Flag)
                  check_unitplace(digit_array, number);
            
            break;
      
      case      3:
            check_hundredplace(digit_array, number);
            if(RouteSelect_Flag)
                  check_tenplace(digit_array, number);
            if(RouteSelect_Flag)
                  check_unitplace(digit_array, number);
            break;
      case 4:
            check_thousandplace(digit_array, number);
            if(WaySelect_Flag)
            {
                  check_hundredplace(digit_array,number);
                        if(RouteSelect_Flag)
                              check_tenplace(digit_array, number);
                        if(RouteSelect_Flag)
                              check_unitplace(digit_array, number);
            }
            break;            
      
      }
      //printf("The number is :%s",OutString);
      TempOut = OutString;
      puts(TempOut);
      return 1;      
}
0
rbrCommented:
digits, PathSelect_Flag, WaySelect_Flag, RouteSelect_Flag not defined.

Post the code of the other functions too, pls!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.