fread

在一张图片中隐藏另一张图片

我的梦境 提交于 2020-01-14 11:42:48
首先是在灰度图中隐藏灰度图 因为是交作业嘛,为了简单就依次在每个字节中隐藏信息,如果有什么不想让人看见的东西要隐藏,可以自己有选择性的隐藏 这里先得到两张灰度图 将第二幅图片当作秘密图片插入一图,这里先将第二幅图置乱 这里采用的是菱形置乱的方法,即在菱形中从第一行开始从左向右依次写入1到n,替换时从第一列从上到下依次读取序号,即第一列序号对应的像素作为第一个像素 代码如下,这里我用的算法比较笨就将就吧,恢复置乱时只需要更改其中一条代码,在代码中已说明 再说明一下,我是将菱形补全为正方形,用0填充,方法虽笨但是能用 /* 对图片进行置乱处理 2015年6月2日20:02:18 blog:http://www.cnblogs.com/wd1001/ */ #include<stdio.h> #include<malloc.h> #include<stdlib.h> /* 位图头结构 */ #pragma pack(1) typedef struct tagBITMAPFILEHEADER { unsigned char bfType[2];//文件格式 unsigned long bfSize;//文件大小 unsigned short bfReserved1;//保留 unsigned short bfReserved2; unsigned long bfOffBits; /

php 文件读取方式

我们两清 提交于 2020-01-10 04:53:32
整理了一下PHP中读取文件的几个方法,方便以后查阅。 1.fread    string fread ( int $handle , int $length )   fread() 从 handle 指向的文件中读取最多 length 个字节。该函数在读取完最多 length 个字节数,或到达 EOF 的时候,或(对于网络流)当一个包可用时,或(在打开用户空间流之后)已读取了 8192 个字节时就会停止读取文件,视乎先碰到哪种情况。   fread() 返回所读取的字符串,如果出错返回 FALSE。 <?php $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r");//读取二进制文件时,需要将第二个参数设置成'rb' //通过filesize获得文件大小,将整个文件一下子读到一个字符串中 $contents = fread($handle, filesize ($filename)); fclose($handle); ?>   如果所要读取的文件不是本地普通文件,而是远程文件或者流文件,就不能用这种方法,因为,filesize不能获得这些文件的大小。此时,你需要通过feof()或者fread()的返回值判断是否已经读取到了文件的末尾。   例如: <?php $handle = fopen(

fread into struct reads data incorrectly

随声附和 提交于 2020-01-06 15:52:50
问题 I am trying to read a bitmap (.bmp) image header into a struct in c. typedef unsigned short WORD; typedef unsigned long DWORD; typedef struct _BITMAPFILEHEADER { WORD Type; DWORD Size; WORD Reserved1; WORD Reserved2; DWORD OffBits; } BITMAPFILEHEADER; My code to read the bitmap file FILE *fp; BITMAPFILEHEADER header; fp = fopen(file,"rb"); if (fp == NULL) { printf("cannot open file!\n"); return 1; } fread(&header, sizeof(BITMAPFILEHEADER), 1, fp); printf("Type: %02x\n", header.Type); printf(

Reading part of a file in C using fread() and fseek()

大兔子大兔子 提交于 2020-01-06 08:12:46
问题 I'm trying to read a file into a buffer in blocks of size BLOCK_SIZE (currently equal to 1000 unsigned chars ). My code initially finds the number of blocks it will have to read in order to read the entire file (usually 2-4), then iterates through a for loop reading the file (ignore the " +17+filenamesize " stuff, that is all needed for later in the program. However, only on the first time, when j=1 , does it actually put data into the buf array. In other cases, when j != 1 , strlen(buf)

Reading part of a file in C using fread() and fseek()

不羁岁月 提交于 2020-01-06 08:12:25
问题 I'm trying to read a file into a buffer in blocks of size BLOCK_SIZE (currently equal to 1000 unsigned chars ). My code initially finds the number of blocks it will have to read in order to read the entire file (usually 2-4), then iterates through a for loop reading the file (ignore the " +17+filenamesize " stuff, that is all needed for later in the program. However, only on the first time, when j=1 , does it actually put data into the buf array. In other cases, when j != 1 , strlen(buf)

fread() reads big number as 4.076092e-309

好久不见. 提交于 2020-01-05 01:35:24
问题 The original numbers are integers from 825010211307012 to 825010304926185 . fread() turns all those numbers to 4.076092e-309 . read.table works normally, but I need to read large data so I can't use it. How can I correct this error? 回答1: If you install the bit64 package then fread will use it to read these large integers: before: > fread("./bignums.txt") V1 1: 4.076092e-309 2: 4.076092e-309 Do the magic: > install.packages("bit64") Then: > fread("./bignums.txt") V1 1: 825010211307012 2:

Fast read different type of data with same command, better seperator guessing [duplicate]

怎甘沉沦 提交于 2020-01-04 14:18:20
问题 This question already has answers here : Reading aligned column data with fread (2 answers) Closed last year . I have LD data, sometimes raw output file from PLINK as below (notice spaces - used to make the output pretty, notice leading and trailing spaces, too): write.table(read.table(text=" CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 1 154834183 rs1218582 1 154794318 rs9970364 0.0929391 1 154834183 rs1218582 1 154795033 rs56744813 0.10075 1 154834183 rs1218582 1 154797272 rs16836414 0.106455 1

C fread binary number and convert it to Ascii code

只谈情不闲聊 提交于 2020-01-04 04:07:28
问题 I'm trying to read the following binary (01100001) from a file and convert it to ascii code (97), but when using fread i'm getting a very big numbers. the file "c:/input.txt" contain only the following line -01100001 printf of the array values print big numbers, such as 825241648 My code: int main() { unsigned int arr[8]; int cnt,i,temp=0; FILE * input; if(!(input=fopen("C:/input.txt","r"))) { fprintf(stderr,"cannot open file\n"); exit(0); } cnt = fread(arr,1,8,input); for(i=0;i<cnt;i++) {

C语言 FileStreaming fwrite&fread

懵懂的女人 提交于 2020-01-03 04:00:12
格式化IO 方法 描述 fprintf Write formatted data to stream (function ) 向文件格式化写入 fscanf Read formatted data from stream (function ) 向文件格式化读出 sprintf Write formatted data to string (function ) 向C字符串读出 sscanf Read formatted data from string (function ) 向C字符串写入 printf Print formatted data to stdout (function ) 向标准输出给石化读出 scanf Read formatted data from stdin (function ) 向标准输入格式化写入 字符字符串IO 参数 描述 fgetc(函数实现) Get character from stream (function ),getc( 宏实现 ) fputc(函数实现) Write character to stream (function ) putc(宏实现) fgets Get string from stream (function ) fputs Write string to stream (function ) getchar Get

fread is signalling EOF prematurely with a binary file

点点圈 提交于 2020-01-03 02:32:27
问题 I'm a newcomer to C. I'm attempting to make my own version of base64 ; the program takes input from stdin and outputs its base64 equivalent to stdout. While testing my program against a binary file, I noticed that fread -ing from stdin seemed to be returning a short count early before actually reaching EOF. Here is the relevant portion of my main method: int main(void) { unsigned char buffer[BUFFER_SIZE]; unsigned char base64_buffer[BASE64_BUFFER]; while (1) { TRACE_PUTS("Reading in data from