[ create a new paste ] login | about

Link: http://codepad.org/yl6Ywfwn    [ raw code | output | fork ]

C, pasted on May 26:
#include<stdio.h>
int main(void)
{
	struct good{
		char name[20];
		char price[5];
	}record;
	FILE *fin,*fout;
	char wname[20];
	int size;
	size=sizeof(record);
	printf("name ?");
	scanf("%s",wname);
	fin=fopen("file1","r");
	if(fin==NULL){
		printf("open error-input file");
		exit(1);
	}
	fout=fopen("file2","w");
	if(fout==NULL){
		printf("open error-input file");
		exit(1);
	}
	while(1){
		fread(&record,size,1,fin);
		if(feof(fin)!=0)break;
		if(strcmp(record.name,wname)==0){
			printf("price=%s\n",record.price);
			scanf("%s",record.price);
		}
		fwrite(&record,size,1,fout);
	}
	fclose(fin);
	fclose(fout);
	printf("update....ended");
	return 0;
}


Output:
1
name ?open error-input file


Create a new paste based on this one


Comments: