Auto commit
This commit is contained in:
		
							parent
							
								
									21eab878bf
								
							
						
					
					
						commit
						1455f339be
					
				
							
								
								
									
										18
									
								
								2207/C语言同步练习源码/8-文件-1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								2207/C语言同步练习源码/8-文件-1.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
	FILE *in, *out;
 | 
			
		||||
	char str[100];
 | 
			
		||||
	in = fopen("file1.c", "r");//r:只读 
 | 
			
		||||
	out = fopen("file2.c", "w");//w:覆盖 
 | 
			
		||||
	
 | 
			
		||||
	while(fgets(str, 100, in)){//fgets每次从文件获取一行并存储到str中 
 | 
			
		||||
		puts(str);//使用控制台输出
 | 
			
		||||
		fputs(str, out);//向file2.c输出 
 | 
			
		||||
	}
 | 
			
		||||
	fclose(in);//关闭文件指针 
 | 
			
		||||
	fclose(out);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										18
									
								
								2207/C语言同步练习源码/8-文件-2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								2207/C语言同步练习源码/8-文件-2.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
	
 | 
			
		||||
	FILE *fp;
 | 
			
		||||
	char ch;
 | 
			
		||||
	int count=0;
 | 
			
		||||
	fp = fopen("letter.txt", "r");
 | 
			
		||||
	while((ch=fgetc(fp)) != EOF){
 | 
			
		||||
		if(ch == 'c'){
 | 
			
		||||
			count++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	printf("c个数为:%d\n", count);
 | 
			
		||||
	
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										9
									
								
								2207/C语言同步练习源码/file1.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								2207/C语言同步练习源码/file1.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										9
									
								
								2207/C语言同步练习源码/file2.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								2207/C语言同步练习源码/file2.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,9 @@
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1
									
								
								2207/C语言同步练习源码/letter.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								2207/C语言同步练习源码/letter.txt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
ccadfadsfasfadsfafa
 | 
			
		||||
@ -1035,12 +1035,53 @@ int main(){
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
```c
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
	FILE *in, *out;
 | 
			
		||||
	char str[100];
 | 
			
		||||
	in = fopen("file1.c", "r");//r:只读 
 | 
			
		||||
	out = fopen("file2.c", "w");//w:覆盖 
 | 
			
		||||
	
 | 
			
		||||
	while(fgets(str, 100, in)){//fgets每次从文件获取一行并存储到str中 
 | 
			
		||||
		puts(str);//使用控制台输出
 | 
			
		||||
		fputs(str, out);//向file2.c输出 
 | 
			
		||||
	}
 | 
			
		||||
	fclose(in);//关闭文件指针 
 | 
			
		||||
	fclose(out);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### 文件-2
 | 
			
		||||
 | 
			
		||||

 | 
			
		||||
 | 
			
		||||
```c
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
int main(){
 | 
			
		||||
	
 | 
			
		||||
	FILE *fp;
 | 
			
		||||
	char ch;
 | 
			
		||||
	int count=0;
 | 
			
		||||
	fp = fopen("letter.txt", "r");
 | 
			
		||||
	while((ch=fgetc(fp)) != EOF){
 | 
			
		||||
		if(ch == 'c'){
 | 
			
		||||
			count++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	printf("c个数为:%d\n", count);
 | 
			
		||||
	
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### 文件-3
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user