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

putc() Function in C Programming Language

putc() 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. putc and fputc are equivalent, except that putc may be implemented as a macro in some libraries. See putchar for a similar function that writes directly to stdout.
Syntax for putc() Function in C
#include <stdio.h> int putc ( int character, FILE * stream );
The int promotion of the character to be written. The value is internally converted to an unsigned char when written. Because some libraries may implement this function as a macro, and this may evaluate the stream expression more than once, this should be an expression without side effects.
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. putc() function is C library function, and it's used to write a character to the file. This function is used for writing a single character in a stream along with that it moves forward the indicator's position.
/* write a character to an output stream by putc() function example */ #include <stdio.h> #include <stdlib.h> int main() { //Initialize the file pointer FILE* f; char ch; //Create the file for write operation f = fopen("myfile.txt", "w"); printf("Enter five character\n"); for (int i = 0; i < 5; i++) { //take the characters from the users scanf("%c", &ch); //write back to the file putc(ch, f); //clear the stdin stream buffer fflush(stdin); } //close the file after write operation is over fclose(f); //open a file f = fopen("myfile.txt", "r"); printf("Write operation is over and file is reday for read operation\n"); printf("\n...............print the characters..............\n\n"); while (!feof(f)) { //takes the characters in the character array ch = getc(f); //and print the characters printf("%c\n", ch); } fclose(f); return 0; }

C program, 'using recursion', performs Matrix multiplication of 2 'matrices' and displays the result. We use 2 D array to represent a matrix & resulting matrix is stored in different matrix

C Language code how to display a table in C programming language is more or less similar to that of counting. We use only one iteration and increment it with value of which table is

There is not any Easy and Direct conversion algorithm from hexadecimal to octal number. Convert the Hex number to Binary. Group the converted binary in groups of 3 bits. Write the