Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C Programming Code Examples

Learn C Language

fputc() Function in C Programming Language

fputc() Function in C
Write character to stream. Writes a character to the stream and advances the position indicator. The character is written at the position indicated by the internal position indicator of the stream, which is then automatically advanced by one. fputc() function is a file handling function in C programming language which is used to write a character into a file. It writes a single character at a time in a file and moves the file pointer position to the next address/location to write the next character.
Syntax for fputc() Function in C
#include <stdio.h> int fputc ( int character, FILE * stream );
The int promotion of the character to be written. The value is internally converted to an unsigned char when written.
Pointer to a FILE object that identifies an output stream. On success, the character written is returned. If a writing error occurs, EOF is returned and the error indicator (ferror) is set.
/* write a character to the stream and advance the position indicator by fputc() function example */ #include<stdio.h> #include<stdlib.h> int main() { int ch; FILE *fp; fp = fopen("myfile.txt", "w"); if(fp == NULL) { printf("Error opening file\n"); exit(1); } printf("Press Ctrl+Z in DOS and Ctrl+D\n\ in Linux to stop reading more characters\n\n"); printf("Enter text: "); while( (ch=getchar()) != EOF ) { fputc(ch, fp); } fclose(fp); return 0; }

C program to search all occurrences of a word in given string using loop. Input string & word from user. Run a Loop from 'starting index' of string to Length of string - word length. Enter

C program to read elements in a matrix and find transpose of the given matrix. How to find transpose of a given matrix in C. Input elements in matrix A from user. Declare...

C programming code asks for the username, password and displays the same to illustrate user authentication. Take the user name and password as input. Print the each character...

C program code example Initialize random number generator: how to use rand/srand. Generating random numbers. Print a number between 0 and 50, print a number between

If a number is exactly divisible by 2 then its an even number else it is an odd number. In this we have shared 2 ways to check whether the input number is even or odd. Using Modulus