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]
- How to use execvp()
- How to use execvp() to execute a command
- what is Segmentation fault (core dumped)? [duplicate]
- uint8_t vs unsigned char
- What is the difference between ++i and i++?
- Using boolean values in C
- What does “collect2: error: ld returned 1 exit status” mean?
- typedef struct vs struct definitions [duplicate]
- What can be the reasons of connection refused errors?
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- What does the question mark character (‘?’) mean?
- makefile:4: *** missing separator. Stop
- What is the difference between C and embedded C?
- Undefined reference to pthread_create
- Difference between malloc and calloc?
- What is Bit Masking?
- segmentation fault : 11
- What are .a and .so files?
- So what does “return 0” actually mean?
- what is the meaning of == sign?
- How do I use extern to share variables between source files?
- Cannot assign requested address – possible causes?
- ARM Assembler – How do I use CMP, BLT and BGT?
- Invalid read of size 8 – Valgrind + C
- error: called object is not a function or function pointer
- munmap_chunk(): invalid pointer
- No Symbol Table using GDB on Compiled Programs
- What is char ** in C?
- What is a bus error? Is it different from a segmentation fault?
- Difference between char* and const char*?
- Output single character in C
- Get the current time in C
- Does connect() block for TCP socket?
- Converting a C program to MIPS
- C: linker command failed with exit code 1
- What’s the equivalent of new/delete of C++ in C?
- sizeof float (3.0) vs (3.0f)
- Get text from user input using C
- How to trigger SIGUSR1 and SIGUSR2?
- warning: expression result unused
- error: indirection requires pointer operand (‘int’ invalid)
- What is the difference between exit(0) and exit(1) in C?
- Display value found at given address gdb
- Array definition – Expression must have a constant value
- How to print a char array in C through printf?
- Constant pointer vs Pointer to constant
- Variable warning set but not used
- Expected declaration specifier error in function
- How to create an array of strings in C?
- C char* to int conversion
- error: aggregate value used where an integer was expected
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- Simple way to check if a string contains another string in C?
- What are .axf files?
- printf format specifiers for uint32_t and size_t
- How to remove first character from C-string?
- error: function returns address of local variable
- What is an simple example of copy_from_user
- What is `S_ISREG()`, and what does it do?
- typedef struct pointer definition
- Math constant PI value in C
- Return a `struct` from a function in C
- The code does not execute properly. Try to figure out why
- ld.exe: cannot open output file … : Permission denied
- How to read from input until newline is found using scanf()?
- What is char ** in C? [duplicate]
- segmentation fault using scanf
- realloc(): invalid next size when reallocating to make space for strcat on char *
- Why cannot cast Integer to String in java?
- How to Compare 2 Character Arrays [duplicate]
- segmentation fault with strcpy [duplicate]