一个关于数组的问题

[复制链接]
查看11 | 回复2 | 2008-8-20 17:19:30 | 显示全部楼层 |阅读模式
这段代码主要是把一个htm的文件读入到一个数组里面 然后用printf直接输出 这样就不用一行一行打印printf了 ,不过我不知道怎样方便的使用数组 只能先给数组规定好了大小 像下面这样。。。。那位高手教我不用定义数组大小 方便的把文件读入数组啊 ?不用数组也可以只要达到我的要求 谢谢了 ~~~
#include "stdio.h"
#include
#include
main()
{
FILE *stream;

char buf[255];
int n;
stream = fopen("voice.htm", "r");
while(!feof(stream))
{
n=fread(buf,1, 255, stream);
stream[n]='\0'
printf("Content-type:text/html\n\n");
printf("%d" ,buf);
}

fclose(stream);
}
2楼的答案通不过编译啊。。。
char buf[200000]={0};
stream = fopen("voice.htm", "r+");
fread(buf,1, 200000, stream);
printf("Content-type:text/html\n\n");
//printf(path);
printf(buf,path1,path,path2);
fclose(stream);
}

回复

使用道具 举报

千问 | 2008-8-20 17:19:30 | 显示全部楼层
不用定义那么大的数组,定义一个小点的,然后循环读就行了#include "stdio.h"void main(){ FILE *fp=fopen("C:/a.htm","r"); char str[81]; int n; while(!feof(fp)) {n=fread(str,sizeof(char),80,fp);str[n]='\0';printf("%s",str); } fclose(fp);}用80,255,4096随便你...
回复

使用道具 举报

千问 | 2008-8-20 17:19:30 | 显示全部楼层
动态分配啊 char *str =new char[]...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行