ANSI使用标准io
#include
#include <stdlib.h>
int main(int argc ,char *argv[])
{
int ch ;
FILE *fp ;
long count = 0;
if (argc != 2 ) {
printf("Usae : %s filename \n",argv[0]);
exit(1);
}
if ((fp = fopen(argv[1], "r")) == NULL) {
printf("Can't open %s \n ",argv[1] );
exit(1);
}
while ((ch = getc(fp)) != EOF) {
putc(ch,stdout);
count++;
}
fclose(fp);
printf("File %s has %ld characters \n ",argv[1] , count);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
void main()
{
int ch ;
FILE *fp ;
fp = fopen(".\\wacky.txt","r");
while((ch = getc(fp)) != EOF)
{
putchar(ch);
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LEN 40
void main( int argc ,char *argv[])
{
FILE *in ,*out;
int ch;
char name[LEN];
int count = 0;
if (argc < 2) {
fprintf(stderr, "Usage:%s fiename\n",argv[0])
;
exit(100);
}
if ((in = fopen(argv[1], "r")) == NULL) {
fprintf(stderr , "I couldnt open the file \"%s\" \n",argv[1]);
exit(2);
}
strcpy(name, argv[1]);
strcat(name,".\\eddy.red");
if ((out = fopen(name, "w")) == NULL) {
fprintf(stderr, "cant create output file \n");
exit(3);
}
while ((ch = getc(in)) != EOF) {
if (count ++ %3 ==0) {
putc(ch,out);
}
}
if (fclose(in ) != 0 || fclose(out) != 0) {
fprintf(stderr, "eror in closing files \n");
}
}
文件重定向
#define use _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
char str[100] = {0};
scanf("%s",str);
printf("%s",str);
system(str);
}
网友评论