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

fseek() Function in C Programming Language

fseek() Function in C
Reposition stream position indicator. Sets the position indicator associated with the stream to a new position. For streams open in binary mode, the new position is defined by adding offset to a reference position specified by origin. For streams open in text mode, offset shall either be zero or a value returned by a previous call to ftell, and origin shall necessarily be SEEK_SET. If the function is called with other values for these arguments, support depends on the particular system and library implementation (non-portable). The end-of-file internal indicator of the stream is cleared after a successful call to this function, and all effects from previous calls to ungetc on this stream are dropped. On streams open for update (read+write), a call to fseek allows to switch between reading and writing. The fseek() function is used to move the cursor in the file to the desired position.
Syntax for fseek() Function in C
#include <stdio.h> int fseek ( FILE * stream, long int offset, int origin );
Pointer to a FILE object that identifies the stream.
Binary files: Number of bytes to offset from origin. Text files: Either zero, or a value returned by ftell.
Position used as reference for the offset. It is specified by one of the following constants defined in exclusively to be used as arguments for this function:
Beginning of file
Current position of the file pointer
End of file * * Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability). If successful, the function returns zero. Otherwise, it returns non-zero value. If a read or write error occurs, the error indicator (ferror) is set.
/* set the position indicator associated with the stream by fseek() function code example */ #include <stdio.h> int main() { FILE *fx; fx = fopen("new_file.txt", "r"); //Using the fseek function to move the file pointer to the end fseek(fx, 0, SEEK_END); // Using the file function in order to Print the position of file pointer printf("Position of file pointer is : "); printf("%ld \n", ftell(fx)); // Using the file function 'fseek' to move the file position 10 characters ahead fseek(fx,10,SEEK_SET); int ch; // printing the resulting file after 10 characters printf("Resulting bytes after the 10 characters in a file are: "); while( (ch=fgetc(fx)) != EOF) // using function 'putchar(x)'' to print the file characters on console putchar(ch); return 0; }

In C programming language we use bitwise AND & operator to check status of any bit. Bitwise AND operation evaluate each bit of resultant value as 1, if corresponding bit of...

Appending, writing files in c programming language. Append the source target. Open the first file for reading. The second file for writing. Copy data from the first file to the

Open first file, open second file then compare the files. If the file won't open giving message Error reading first file or Error reading second file. Files differ at byte number or files are the

Code Count the number of Occurrences of an element in the linked list using recursion. This C Program uses recursive function & finds the occurrence for an element in an Unsorted list.

In program we're going to accept 2 numbers from user using pointer. After accepting Two Numbers we are going to add Two Numbers by using "De-reference Operator" in Pointer.