69,336
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
FILE *fp2;
fp2=fopen("stdout","a+");
char count=48;
char ch;
if((fp=fopen("stdin","wb+"))==NULL)
{
printf("can not open the file");
exit(0);
}
ch=getchar();
ch=getchar();
while(ch!=EOF)
{
fputc(ch,fp);
ch=getchar();
if(ch=='$')
count++;
}
ch=fgetc(fp2);
fputc(ch,fp2);
fclose(fp);
fclose(fp2);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *in, *out;
in = fopen("./stdin", "r");
if(in == NULL){
exit(-1);
}
out = fopen("./stdout", "a");
if(out == NULL){
exit(-1);
}
int ch, cnt = 0;
while((ch = fgetc(in)) != EOF){
(void)fputc(ch, out);
if(ch == '$'){
cnt++;
}
}
(void)fclose(in);
(void)fclose(out);
printf("\'$\' exsit %d times\n", cnt);
return 0;
}
'$' exsit 3 times
#include <stdio.h>
#include <stdlib.h>
int main()
{
/*
FILE *fp;
FILE *fp2;
fp2 = fopen("stdout","a+");
char count=48;
char ch;
if((fp=fopen("stdin","wb+"))==NULL) {
printf("can not open the file");
exit(0);
}
*/
int count = 0, ch;
ch = getchar();
while (ch != EOF)
{
fputc(ch, stdout);
ch = getchar();
if(ch == '$')
count++;
}
printf("%d\n", count);
/*
fclose(fp);
fclose(fp2);
*/
return 0;
}
标准输入输出已经是打开状态,不需要再打开。
标准输入比如键盘,标准输出比如终端,显示器等。