将一个txt文档中所有字符读入一个数组中的代码
2008-01-31 23:42
337 查看
FILE* f = fopen("filename", "rb");
// get file length
fseek(f, SEEK_END, 0);
const int len = ftell(f);
fseek(f, SEEK_SET, 0);
// read file
char* buf = new char[len + 1];
fread(buf, 1, len, f);
fclose(f);
buf[len] = 0;
// remove /r and /n
char* buf_1 = buf;
char* buf_2 = buf;
while (*buf_1 != '/0') {
if (*buf_1 != '/r' && *buf_1 != '/n')
*(buf_2++) = *buf_1;
buf_1 ++;
} // while
*buf_2 = '/0';
// get file length
fseek(f, SEEK_END, 0);
const int len = ftell(f);
fseek(f, SEEK_SET, 0);
// read file
char* buf = new char[len + 1];
fread(buf, 1, len, f);
fclose(f);
buf[len] = 0;
// remove /r and /n
char* buf_1 = buf;
char* buf_2 = buf;
while (*buf_1 != '/0') {
if (*buf_1 != '/r' && *buf_1 != '/n')
*(buf_2++) = *buf_1;
buf_1 ++;
} // while
*buf_2 = '/0';
相关文章推荐
- 求解一个字符串的所有字符的组合 Java代码
- 使用jQuery匹配文档中所有的li元素,返回一个jQuery对象,然后通过数组下标的方式读取jQuery集合中第1个DOM元素,此时返回的是DOM对象,然后调用DOM属性innerHTML,读取该元素 包含的文本信息
- 第二周第四天(解析/过滤文件/找d盘里的所有txt文件/FileInputStream/FileOutputStream/拷贝文件/readLine读取一个文本行/在一个文档里写入内容)
- 7、定义一个文件输入流,调用read(byte[] b) 方法将exercise.txt文件中的所有内容打印出来(byte数组的大小限制为5,不考虑中文编码问题)。
- C#新手入门代码 控制台使用console.read读入一个字符
- (详版, 无bug版)有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)
- 有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)。
- 2、有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)。
- 编写一个程序,从标准输入读入字符,并把它们写出在标准输出中。 所有非字母字符都完全按照它的输入形式输出,字母字符在输出前进行加密
- 找出一个字符数组(元素不重复)所有可能字符的组合
- 定义一个文件输入流,调用 read(byte[] b)方法将 exercise.txt 文件中的所有内容打印出来 (byte 数组的大小限制为 5)。
- 串中取3个不重复字母 从标准输入读入一个由字母构成的串(不大于30个字符)。 从该串中取出3个不重复的字符,求所有的取法。
- (指针版,无bug版)有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)
- 给定一个字符数组,求由这些字符组成的所有不同的排序问题.
- 9.1数组与字符串(一)——确定一个字符串的所有字符是否完全不同
- 用JAVA编写一个算法实现对一个字符数组的所有元素的所有组合
- 十进制转化成2,8,16进制数工具。将代码全部复制到一个txt文档中保存,并将文件后缀.txt改为.html,再浏览器打开即可
- 3、有一段文本,将文本中的所有单词,存放到一个字符指针数组中(要求每个单词内存恰好)
- 编写一个程序读入一行输入,然后反向打印该行,您可以把输入存储在一个char数组中: 假定该行不超过255个字符。回忆一下,您可以使用具有%c说明符的scanf()从输入中一次 读入一个字符,而且当您按
- TXT数据文档读入,存入数组