关于C语言中文件与变量的概念疑惑,是否变量都同等于文件,还是说只有后缀名的才能成为文件
C Primer Plus 13.2reucto.cpp程序中,变量同等与文件?变量是一种类型,文件是磁盘/硬盘的存储区,是同等的吗?
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 40
int main(int argc,char *argv[])
{
FILE *in,*out;
int ch;
char name[LEN];
int count=0;
if(argc<2)
{
fprintf(stderr,"Usage: %s filename\n",argv[0]);
exit(EXIT_FAILURE);
}
if((in=fopen(argv[1],"r"))==NULL)
{
fprintf(stderr,"I couldn't open the file \"%s\"\n",argv[1]);
exit(EXIT_FAILURE);
}
strncpy(name,argv[1],LEN-5);//这就能创造文件?
name[LEN-5]='\0';
strcat(name,".red");
if((out=fopen(name,"w"))==NULL)
{
fprintf(stderr,"Can't creat output file.\n");
exit(3);
}
while((ch=getc(in))!=EOF)
if(count++%3==0)
putc(ch,out);
while((ch=getc(out))!=EOF)
putchar(ch);
if(fclose(in)!=0||fclose(out)!=0)
fprintf(stderr,"Error in closing files\n");
return 0;
}