FILE *f = fopen("file.txt", "w"); if (f == NULL) { printf("Error opening file!\n"); exit(1); } /* print some text */ const char *text = "Write this to the file"; fprintf(f, "Some text: %s\n", text); /* print integers and floats */ int i = 1; float pi= 3.1415927; fprintf(f, "Integer: %d, float: %f\n", i, pi); /* printing single chatacters */ char c = 'A'; fprintf(f, "A character: %c\n", c); fclose(f);
Related Posts:
- Why does ENOENT mean “No such file or directory”?
- Undefined reference to pthread_create in Linux
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Openssl : error “self signed certificate in certificate chain”
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- What is the LD_PRELOAD trick?
- connect Error: “No route to host”
- The difference between stdout and STDOUT_FILENO
- Does connect() block for TCP socket?
- where does stdio.o live in linux machine?
- Linux equivalent of I_PUSH
- Display value found at given address gdb
- What can cause a “Resource temporarily unavailable” on sock send() command
- Efficient way to find task_struct by pid
- valgrind – Address —- is 0 bytes after a block of size 8 alloc’d
- error: aggregate value used where an integer was expected
- What is `S_ISREG()`, and what does it do?
- execvp: bad address error
- GDB no such file or directory
- Implementing Taylor Series for sine and cosine in C
- warning: implicit declaration of function
- pthread_join() and pthread_exit()
- Why should we typedef a struct so often in C?
- What is the difference between ++i and i++?
- Stack smashing detected
- Why am I getting “void value not ignored as it ought to be”?
- Pointer Arithmetic
- dereferencing pointer to incomplete type
- Get a substring of a char* [duplicate]
- How do I create an array of strings in C?
- How do function pointers in C work?
- “Expected expression before ‘ { ‘ token”
- How to generate a random int in C?
- How do I use valgrind to find memory leaks?
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- What is the difference between char s[] and char *s?
- Error “initializer element is not constant” when trying to initialize variable with const
- munmap_chunk(): invalid pointer
- What is the argument for printf that formats a long?
- Cannot assign requested address – possible causes?
- Using %s in C correctly – very basic level
- How do you make an array of structs in C?
- need help understanding the movzbl call in this function
- How to extract C source code from .so file?
- How to create my own header file in c++?
- warning: implicit declaration of function
- C dynamically growing array
- Returning string from C function
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- Char Comparison in C
- what is the unsigned datatype?
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- Reading a string with scanf
- How to initialize a struct in accordance with C programming language standards
- Expression preceding parentheses?
- Understanding INADDR_ANY for socket programming
- getopt_long() — proper way to use it?
- C read file line by line
- The Definitive C Book Guide and List[
- When is it a good idea to use strdup (vs malloc / strcpy)
- C read file line by line
- Copying a part of a string (substring) in C
- expression must have integral type
- Incompatible implicit declaration of built-in function ‘malloc’
- Why is %c used in C?
- Need more information about Aborted (core dumped)
- What is Innermost loop in imperfectly nested loops?
- What’s wrong with my code? What is argv[1]?
- Reversing a string in C
- When a number is written as 0x00… what does the x mean
- How to remove the character at a given index from a string in C?
- waitpid, wnohang, wuntraced. How do I use these
- Split string with delimiters in C
- How to pause in C?
- (.text+0x20): undefined reference to `main’ and undefined reference to function
- Why am I getting this error: “data definition has no type or storage class”?
- I’m getting “Invalid Initializer”, what am I doing wrong?
- Writing binary number system in C code
- Error: initializer element is not computable at load time
- Convert char array to string use C
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- Scanning Multiple inputs from one line using scanf
- Read and write to binary files in C?
- Which of sprintf/snprintf is more secure?
- Where is the
header file on Linux? Why can’t I find ? - Allocating char array using malloc
- Implementation of strtok() function
- C fopen vs open
- switch case: error: case label does not reduce to an integer constant
- warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
- warning: return makes pointer from integer without a cast but returns integer as desired
- The difference between char * and char[] [duplicate]
- How to clear input buffer in C?
- What primitive data type is time_t? [duplicate]
- Usage of \b and \r in C
- Parsing command-line arguments in C
- Compiler warning – suggest parentheses around assignment used as truth value
- How to use shared memory with Linux in C
- lvalue required as increment operand