Difference between revisions of "Crise cad.c"

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
(New page: <code lang="c"> #include <stdio.h> struct folha { char servidor[51]; int idade; int salario; }; int main(void) { FILE *fp = fopen("crise.dat","a+"); int i,n; struct folha *fl, *tb;...)
 
(No difference)

Latest revision as of 21:39, 12 June 2009

#include <stdio.h>
 
struct folha
{
	char servidor[51];
	int idade;
	int salario;
};
 
int main(void)
{
	FILE *fp = fopen("crise.dat","a+");
	int i,n;
	struct folha *fl, *tb;
 
	scanf("%d",&n);
	fl=malloc(sizeof(struct folha)*n);
 
	for(i=0,tb=fl;i<n;i++,tb=fl+i)
		scanf("%s %d %d",tb->servidor,&(tb->idade),&(tb->salario));
 
	fwrite(fl,sizeof(struct folha),n,fp);
	free(fl);
 
	fclose(fp);
 
	return 0;
}