So I am trying to read the words from a file. However, I have to use `putchar(ch)` where `ch` is an `int`. How do I convert ch to a string (char \*) so I can store it in a char \* variable and pass it to another function that takes char \* as a parameter. And I actually just want to store it but not print it.

This is what I have:

```
int main (void)
{
   static const char filename[] = "file.txt";
   FILE *file = fopen(filename, "r");
   if ( file != NULL )
   {
      int ch, word = 0;
      while ( (ch = fgetc(file)) != EOF )
      {
         if ( isspace(ch) || ispunct(ch) )
         {
            if ( word )
            {
               word = 0;
               putchar('\n');
            }
         }
         else
         {
            word = 1;
            putchar(ch);
         }
      }
      fclose(file);
   }
   return 0;
}

```
['https://Stackoverflow.com/questions/31778365', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4807625/']
`sprintf(char_arr, "%d", an_integer);`

This makes `char_arr` equal to string representation of `an_integer`
(This doesn't print anything to console output in case you're wondering, this just 'stores' it)
An example:

```
char char_arr [100];
int num = 42;
sprintf(char_arr, "%d", num);

```

`char_arr` now is the string `"42"`. `sprintf`automatically adds the null character `\0` to `char_arr`.

If you want to append more on to the end of char\_arr, you can do this:

```
sprintf(char_arr+strlen(char_arr), "%d", another_num);

```

the '+ strlen' part is so it starts appending at the end.

more info here: <http://www.cplusplus.com/reference/cstdio/sprintf/>
You can use math functions to do that. Like this:

```
#include <stdio.h> // For the sprintf function
#include <stdlib.h> // for the malloc function
#include <math.h> // for the floor, log10 and abs functions

const char * inttostr(int n) {
    char * result;
    if (n >= 0)
        result = malloc(floor(log10(n)) + 2);
    else
        result = malloc(floor(log10(n)) + 3);
    sprintf(result, "%d", n);
    return result;
}

```