//FILE *fopen(char *pname,char *mode)
using namespace std;
FILE *fopen();
int main()
{
FILE *fp;
if((fp=fopen("d:/test.txt","r"))==NULL){
printf("The file can not be opened.\n");
exit(1);
}
else{
printf("I catch U!");
}
return 0;
}
//FILE *fopen(char *pname,char *mode)
using namespace std;
FILE *fopen();
int main()
{
FILE *fp;
fp=fopen("d:/test.txt","r");
fclose(fp);
return 0;
}
//FILE *fopen(char *pname,char *mode)
using namespace std;
FILE *fopen();
int main(int argc, char *argv[])
{
int ch;
FILE *fp;
if(argc!=2){
printf("Error format,Usage:display filename1\n");
return 0;
}
if( (fp=fopen(argv[1],"r"))==NULL ){
printf("The file <%s> can not be opend.\n",argv[1]);
return 0;
}
ch = fgetc(fp);
while(ch != EOF){
putchar(ch);
ch=fgetc(fp);
}
fclose(fp);
}
#include <bits/stdc++.h>
using namespace std;
FILE *fopen();
int main(int argc, char *argv[])
{
int ch;
FILE *in, *out;
if(argc!=3){
printf("Error in format,Usage:copyfile filename1 filename1\n");
return 0;
}
if( (in=fopen(argv[1],"r"))==NULL ){
printf("The file <%s> can not be opend.\n",argv[1]);
return 0;
}
if( (out=fopen(argv[2],"r"))==NULL ){
printf("The file <%s> can not be opend.\n",argv[2]);
return 0;
}
ch = fgetc(in);
while(ch != EOF){
fputc(ch,out);
ch=fgetc(in);
}
fclose(in);
fclose(out);
}
//FILE *fopen(char *pname,char *mode)
using namespace std;
FILE *fopen();
int main(int argc, char *argv[])
{
char str[9];
int ch, count, i;
FILE *fp;
if(argc!=2){
printf("Error in format,Usage:copyfile filename\n");
return 0;
}
if( (fp=fopen(argv[1],"r"))==NULL ){
printf("The file <%s> can not be opend.\n",argv[1]);
return 0;
}
count = 0;
do{
i=0;
printf("%06o:",count*8);
do{
ch=fgetc(fp);
printf("%4d",ch);
if(ch<' ' || ch>'~') str[i]='#';
else str[i]=ch;
if(++i==8) break;
}while(ch!=EOF);
str[i]='\0';
for(;i<8;i++) printf(" ");
printf(" %s\n",str);
count++;
}while(ch!=EOF);
fclose(fp);
}