Prints the integer value with commas to the file stream out

Prints the integer value with commas to the file stream out and returns the number of characters printed The result (e.g. 12,345) must printed character by character using the provided char out function. So when value 12345 you\'ll print 1\', \'2\', \'r\', \'3\', \'4\' and \'5\', one by one To convert a digit (int) between 0 9 to a character simply add \'0\', e. g. 9 \'0\' results in 19 We\'ll discuss conversions like this in class Example usage print with commas (stdout, 1) prints 1 to the screen and returns 1 print with commas (stdout, 123) prints 123 to the screen and returns 3 print with commas (stdout, 1234) prints 1, 234 to the screen and returns 5 print with commas (stdout, 12345) prints 12, 345 to the screen and returns 6 Pre Points to an already opened file stream out value Has been initialized Post value is printed with commas using the provided char out function Restrictions You MUST use the provided char out function when printing You may NOT use other I/O, e.g. any printf or scanf variants You may NOT make any use of character/ string variables or arrays You may NOT use math.h or string h, nor any function declared within You may NOT use any additional libraries You may NOT use recursion

Solution

#include<stdio.h>
void char_out(int value);
int main()
{
char_out(1234567);
return 0 ;
}
void char_out(int value)
{

int mu = 0;
int i = 0;
int divi =10;
int in=0;
int rem =0;
while((value/divi)>0)
{
i++;
divi*=10;
}
i++;
divi /= 10;
in = i%3;
rem = i/3;
if(in==0)
rem--;
in = i+rem;
int j=0;
for(j;j<in;j++)
{
mu = value/divi;
printf(\"%c\",(char)(mu+48));
value -= (mu*divi);
divi /= 10;
i--;
if(i>0&&i%3==0)
{
j++;
printf(\"%c\",\',\');
}
}

}

 Prints the integer value with commas to the file stream out and returns the number of characters printed The result (e.g. 12,345) must printed character by cha

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site