EDIT: As pointed out in the comment, itoa()
is not a standard, so better use sprintf() approach suggested in the rivaling answer!
You can use itoa()
function to convert your integer value to a string.
Here is an example:
int num = 321; char snum[5]; // convert 123 to string [buf] itoa(num, snum, 10); // print our string printf("%s\n", snum);
If you want to output your structure into a file there is no need to convert any value beforehand. You can just use the printf format specification to indicate how to output your values and use any of the operators from printf family to output your data.
Related Posts:
- How to convert an int to string in C?
- How to convert an int to string in C?
- How does strtok() split the string into tokens in C?
- What is a string of hexadecimal digits?
- How to convert a string to integer in C?
- How do I create an array of strings in C?
- What is the difference between char s[] and char *s?
- How do I properly compare strings in C?
- How to convert an int to string in C?
- Returning string from C function
- How do I create an array of strings in C?
- Return char[]/string from a function [duplicate]
- How to check if a string is a number?
- How to convert integer to string in C?
- How do I lowercase a string in C?
- Return char[]/string from a function
- How to clear all the elements of array in C?
- How do I concatenate const/literal strings in C?
- Reversing a string in C
- How to remove the character at a given index from a string in C?
- Split string with delimiters in C
- Check if input is integer type in C
- Allocating string with malloc
- Removing trailing newline character from fgets() input
- Does C have a string type?
- How to concatenate string and int in C?
- warning: return makes pointer from integer without a cast but returns integer as desired
- The difference between char * and char[] [duplicate]
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Get a substring of a char*
- What causes the Broken Pipe Error?
- What is EOF in the C programming language?
- Why does the terminal show “^[[A” “^[[B” “^[[C” “^[[D” when pressing the arrow keys in Ubuntu?
- Reading from file using read() function
- What is the difference between ++i and i++?
- warning: assignment makes integer from pointer without a cast
- munmap_chunk(): invalid pointer
- printf() formatting for hexadecimal
- The importance of c enumeration (typedef enum) [duplicate]
- How do I properly compare strings in C?
- Undefined reference to pow( ) in C, despite including math.h [duplicate]
- Undefined reference to pow( ) in C, despite including math.h [duplicate]
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- C programming, error: called object is not a function or function pointer
- Process finished with exit code 11 | Error during malloc [duplicate]
- How does wait(NULL) exactly work?
- What does strcmp() exactly return in C?
- How to replicate vector in c?
- C compile error: “Variable-sized object may not be initialized”
- What does WEXITSTATUS(status) return?
- Difference between a Structure and a Union
- Xcode – Warning: Implicit declaration of function is invalid in C99
- Error: control may reach end of non-void function in C
- C language: float % float why expression must have integral type
- Reading \r (carriage return) vs \n (newline) from console with getc?
- Invalid pointer error on invoking free() after malloc in C
- In C, how should I read a text file and print all strings
- What does “Size in TCHARs” means?
- return makes integer from pointer without a cast [-Wint-conversion] return candidate
- Math constant PI value in C
- How can I use an array of function pointers?
- When and why to use malloc?
- Multiple definition of … linker error
- Does sizeof return the number of bytes or the number of octets of a type in C?
- C compile error: Id returned 1 exit status
- Efficient way to find task_struct by pid
- Why am I getting this memory access error ‘double free or corruption’?
- Passing an array by reference in C?
- size of struct in C
- Warning: return from incompatible pointer type in C
- How to generate a random number between 0 and 1?
- int cannot be converted to string?
- How can one print a size_t variable portably using the printf family?
- How to make sense of modulo in c
- “No such file or directory” error in CodeBlocks
- Iterate through a C array
- Uninitialized value was created by a heap allocation
- Makefile:1: *** missing separator. Stop
- xorl %eax – Instruction set architecture in IA-32
- Trim a string in C [duplicate]
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- execvp: bad address error
- How detect malloc failure?
- Tokenizing strings in C
- How to display hexadecimal numbers in C?
- Standard function to replace character or substring in a char array?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- Dereference void pointer
- Use of flag in c?
- Split string with multiple delimiters using strtok in C
- How do I check if a string contains a certain character?
- fgetc(stdin) in a loop is producing strange behaviour
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory
- How to convert integers to characters in C?