[ create a new paste ] login | about

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

C, pasted on Jan 7:
#include<stdio.h>
#include<conio.h>

void NhapMangTuFile(char TenFile[], int &n, int a[])
{
	FILE* f;   
	f = fopen(TenFile, "r");
	if(f == NULL)
	{
		printf("\nKhong doc duoc file");
		fclose(f);
		return;
	}

	fscanf(f, "%d", &n);
	for(int i = 0; i < n; i++)
	{
		fscanf(f, "%d", &a[i]);
	}
	fclose(f);
}

void XuatMang(int n, int a[])
{
	for(int i = 0; i < n; i++)
	{
		printf("%4d", a[i]);
	}
	printf("\n");
}

void XuatMangRaFile(char TenFile[], int n, int a[])
{
	FILE* f;  f = fopen(TenFile, "w");
	if(f == NULL)
	{
		printf("\nKhong tao duoc file\n");
		fclose(f);
		return;
	}
	for(int i = 0; i < n; i++)
	{
		fprintf(f, "%4d", a[i]);
	}
	fclose(f);
}
int main()
{
	int n;
	int a[100];

	NhapMangTuFile("input.txt", n, a);
	printf("\nMang da nhap");
	XuatMangRaFile("output.txt", n, a);

	getch();
	return 0;
}


Output:
1
2
3
4
5
6
Line 17: error: conio.h: No such file or directory
Line 4: error: expected ';', ',' or ')' before '&' token
In function 'XuatMang':
Line 25: error: 'for' loop initial declaration used outside C99 mode
In function 'XuatMangRaFile':
Line 41: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: