- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试通过 UART 从 Matlab 将数据从包含十六进制字符的文件复制到嵌入式设备的 SRAM 内存。问题是我不知道如何使程序停止将任何收到的字符视为特殊命令。
例如:根据 ASCII 表,符号 '' 的十六进制相当于 0x20。然而,我的数据可能在某个地方有这个 0x20。因此,我不能使用它作为我的程序的分隔符。
请建议我一种方法,可以读取十六进制文件中的所有数据,而不会导致任何此类问题。
这是我的代码的一部分。
memcpy(((uint8_t*)(SRAM_BASE+i)),&cThisChar,1);
UARTCharPut(UART0_BASE, cThisChar);
i++;
//
// Stay in the loop until either a CR or LF is received.
//
}
while((cThisChar != '\n') && (cThisChar != '\r')); // this is where the problem happens!
那么我应该为 while 循环设置什么条件才能接受所有字符?
谢谢!
最佳答案
不要尝试通过文件内容获取文件结尾。获取其大小并使用计数器代替。
FILE *fp = NULL;
long int fsize = 0;
long int fptr = 0;
/* Open file. */
/* todo: Open file here. */
/* Get file size. */
fseek(fp, 0L, SEEK_END);
fsize = ftell(fp);
fseek(fp, 0L, SEEK_SET);
/* Process file data. */
while (fptr < fsize) {
/* todo: Do your stuff here. */
++fptr;
}
/* Close file. */
/* todo: Close file here. */
关于c - 使用 fread 从 Matlab 读取所有字符到嵌入式设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289184/
我有以下代码: int main() { char* pedal[20]; char* pedal2[20]; for (int i = 0; i < 20; i++)
我想用 in.wav 文件中的数据填充 hdr (结构)变量,并且我想复制 in 的前 64 个字节。 wav 文件转换为另一个文件 (out.wav)。 但是!当第二次使用fread()时,它开始从
我有一个由 1and1 托管的网站 - 他们没用!由于某种原因,他们提供的备份脚本不再有效,他们无法为我提供答案!所以我想我会自己写,这是我的代码: if (file_exists('backup
我正在尝试从文件中读取并将其复制到另一个文件。我正在网上查看一些代码,我似乎注意到有些人以这种方式声明 fread: fread (buffer, 1, 1000, src) 一些这样 fread (
当我是“男人的恐惧”时,我得到了: RETURN VALUE fread() and fwrite() return the number of items successfully read or
从文件中读取整数值时,覆盖率检查给出以下错误 调用函数“fread”会污染参数“readval” //coverity note: Calling function "fread" taints ar
为了更清楚地说明这一点,我将放置代码示例: $file = fopen('filename.ext', 'rb'); // Assume $pos has been declared // metho
尝试转换此 matlab 代码: fid = fopen([fpath, '/file.bin'],'rb'); content = fread(fid, 11,'single'); 我当前的尝试如下
假设我有: FILE* fp = fopen("myfile.bin", "r"); char something[30]; fread(something,sizeof(char)*30,1,fp)
fwrite 一个整数取决于字节序,但是有没有一种方法可以将一个整数 0x00000004 写入一个文件,这样无论它运行在什么机器上,它都可以始终被读取为 0x00000004。 一个想法是始终按照特
所以我尝试将此类 Matlab 代码转换为 C++: ss = 'file.mask' fp = fopen(ss, 'rb'); sx = fread(fp, 1, 'int32') sy = f
使用 C,可以使用函数 fread 来读取以 null 结尾的字符串吗? 我必须读取一个以 ip 开头的文件,该文件是 4 个无符号字符,后跟一个描述空终止字符串数的整数。之后,我需要读取字符串,直到
> fread('col1,col2\n') Empty data.table (0 rows) of 2 cols: col1,col2 > fread('col1,col2\n5,4') c
我正在尝试使用 data.table 将文件读入 R/fread .一些字段有前导零,我只想将数据作为字符读取并手动修复它们。但是我不知道如何将其传达给 fread .我正在尝试这个,它像往常一样分配
fread来自 data.table包一般可以在读取文件时自动确定列分隔符( sep )。 例如,这里fread自动检测 |作为列分隔符: library(data.table) fread(past
使用 fread,如何读取包含行名和列名的 CSV 文件。 我尝试了以下操作,但它没有正确读取行和列名称。 csv 文件看起来像(其中 C1、C2、C3 是列名,r1、r2、r3 是行名) input
我遇到了这样的文件: COL1 COL2 COL3 weqw asrg qerhqetjw weweg ethweth
我正在尝试使用 fread 读取表格。 txt 文件具有如下所示的文本: "No","Comment","Type" "0","he said:"wonderful|"","A" "1","Pr/ "
我正在尝试使用从 Apple 移动性报告生成的 csv,可以找到 here . 现在一切正常,我能够按预期获得 .csv,它看起来像这样的文字: csvtxt <- "geo_type,region,
我在 data.table (1.8.8, R 3.0.1) 中使用 fread 试图读取非常大的文件。 有问题的文件有 313 行和约 660 万列数字数据行,文件大小约为 12GB。这是具有 51
我是一名优秀的程序员,十分优秀!