[ create a new paste ] login | about

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

C, pasted on Dec 19:
#include<stdio.h>
#include<conio.h>
#include<ctype.h>

void UpcaseFile(FILE* inoutFile)
{
	char ch;
	long pos;
	while(!feof(inoutFile))
	{
		ch = fgetc(inoutFile);            // đọc ký tự hiện hành
		if(feof(inoutFile)){
			break;
		}
		pos = ftell(inoutFile);              // ghi nhận vị trí đọc ghi hiện tại
		fseek(inoutFile, pos - 1, SEEK_SET); // dời vị trí đọc ghi lên trước
		ch = toupper(ch);                    // đổi sang ký tự hoa
		fputc(ch, inoutFile);                // ghi ký tự
		fseek(inoutFile, pos, SEEK_SET);    // dời vị trí đọc ghi về chỗ cũ
	}
}
void main()
{
	char* fname = "Data.txt";
	FILE* fpInOut = fopen(fname, "r + b");
	if(fpInOut == NULL)
	{
		printf("File %s not found!\n", fname);
		return;
	}
	UpcaseFile(fpInOut);
	fclose(fpInOut);
	getch();
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'main':
Line 23: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: