用C语言编写“读取一个给定的文本文件,并将文件的内容显示在屏幕上”的一个程序,用vc++6.0运行,谢谢各
3个回答
展开全部
/*楼上的题目会误人子弟的,这样肯定没法过关,下面的才可以!*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define szBUF 256
int main(int argc, char * argv[])
{
char filename[szBUF], buf[szBUF]; int r = 0; FILE * f = 0;
if(argc < 2) {
printf("please input the file name:");
gets(filename);
}else
strcpy(filename, argv[1]);
//end if
f = fopen(filename, "r");
if(!f) {
printf("file %s open fault!\n", filename);
return 0;
}//end if
while(!feof(f)) {
r = fread(buf, sizeof(char), szBUF, f);
if(r < 1) break;
fwrite(buf, sizeof(char), r, stdout);
}//end while
fclose(f);
system("pause");
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define szBUF 256
int main(int argc, char * argv[])
{
char filename[szBUF], buf[szBUF]; int r = 0; FILE * f = 0;
if(argc < 2) {
printf("please input the file name:");
gets(filename);
}else
strcpy(filename, argv[1]);
//end if
f = fopen(filename, "r");
if(!f) {
printf("file %s open fault!\n", filename);
return 0;
}//end if
while(!feof(f)) {
r = fread(buf, sizeof(char), szBUF, f);
if(r < 1) break;
fwrite(buf, sizeof(char), r, stdout);
}//end while
fclose(f);
system("pause");
return 0;
}
展开全部
#include <iostream>
using namespace std;
int main() {
freopen("text.txt","r",stdin);
char str[1024];
cin >> str;
cout << str;
system("pause");
return 0;
}
简单可行……
using namespace std;
int main() {
freopen("text.txt","r",stdin);
char str[1024];
cin >> str;
cout << str;
system("pause");
return 0;
}
简单可行……
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
#include <stdlib.h>
void main ( void )
{
char fileName[] = "file_to_be_read.txt";
char cmd[1024];
sprintf ( cmd, "type \"%s\"", fileName );
system ( cmd );
}
#include <stdlib.h>
void main ( void )
{
char fileName[] = "file_to_be_read.txt";
char cmd[1024];
sprintf ( cmd, "type \"%s\"", fileName );
system ( cmd );
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询