IO进程线程day1

IO进程线程day1_第1张图片

#include 
#include 
#include 
//void Count_f(FILE *fp);
int Count_f(char *s);
int Numl_f(char *s);
int main(int argc, const char *argv[])
{
	char s[10];
	printf("please enter name of file:");
	scanf("%s",s);
	int count = Count_f(s);
	int numl = Numl_f(s);
	printf("%s大小为%d 行数为%d\n",s,count,numl);
	return 0;
}
/*
void Count_f(FILE *fp)
{
	int c;
	int numl = 0;
	int count = 0;
	while(1){
		c = fgetc(fp);
		if(c == EOF)
			break;
		count++;
		if(c == '\n')
			numl++;
	}
	printf("大小为%d 行数为%d\n",count,numl);
}
*/
int Count_f(char *s)
{
	FILE *fp = fopen(s,"r");
	if(NULL == fp){
		perror("fp");
		return -1;
	}
	int c;
	int count = 0;
	while(1){
		c = fgetc(fp);
		if(c == EOF){
			break;
		}
		count++;
	}
	return count;
}
int Numl_f(char *s)
{
	FILE *fp = fopen(s,"r");
	if(NULL == fp){
		perror("fp");
		return -1;
	}
	int c;
	int numl = 0;
	while(1){
		c = fgetc(fp);
		if(c == EOF){
			break;
		}else if(c == '\n'){
			numl++;
		}
	}
	return numl;
}

IO进程线程day1_第2张图片

你可能感兴趣的:(c#)