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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rbrConnect With a Mentor Commented:
Can you pls post the code. For printing a string use

printf ("%s",varname);
0
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
All Courses

From novice to tech pro — start learning today.