Search
 
SCRIPT & CODE EXAMPLE
 

C

fread

#include <stdio.h>

#define n 1024 // n bytes

int main(void) {
	FILE *fp;
    size_t numread;
    if ((fp = fopen("yourfile.xy", "rb") != NULL) {
    	char buffer[n];
        numread = fread(buffer, sizeof(*buffer), n, fp);
      	printf("Read %d Bytes: %s", numread, buffer);
      
      	fclose(fp);
      	return 0;
    }
        
    return -1;
}
Comment

fread

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Comment

fread

//from tutorialspoint.com
#include <stdio.h>
#include <string.h>

int main () {
   FILE *fp;
   char c[] = "this is tutorialspoint";
   char buffer[100];

   /* Open file for both reading and writing */
   fp = fopen("file.txt", "w+");

   /* Write data to the file */
   fwrite(c, strlen(c) + 1, 1, fp);

   /* Seek to the beginning of the file */
   fseek(fp, 0, SEEK_SET);

   /* Read and display data */
   fread(buffer, strlen(c)+1, 1, fp);
   printf("%s
", buffer);
   fclose(fp);
   
   return(0);
}
Comment

PREVIOUS NEXT
Code Example
C :: how to print % in c 
C :: print 100 times c 
C :: C program to find power of any number 
C :: how to join an array of strings c 
C :: vifm preview images 
C :: Relational Operator in C language 
C :: function that changes all lowercase letters of a string to uppercase. 
C :: struct in struct 
C :: how to debug a segmentation fault in c 
C :: string in c 
C :: objects in oops 
C :: man strstr 
C :: convert python to c 
C :: pipe system call 
C :: fifo page algorithm in C 
C :: spacemacs start server 
C :: retoure a la ligne C 
C :: onvert a string into 2d string in c 
C :: uninstall elgg from hostgtor 
C :: how to stop aws alb temporarily 
C :: buble sort in c that ask user input 
C :: Program to Find Swap Numbers Using Temporary Variable 
C :: list fiter octobercms 
C :: passing an array to a function 
C :: wait system call 
C :: Uri/Beecrowd problem no - 1149 solution in C 
C :: listas enlazadas/ linked lists 
C :: pygraphviz show 
C :: vs code turn off formatter 
C :: C Macros using #define 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =