Dạo gần đây mình có làm 1 bài tập về chuẩn hoá văn bản viết bằng C. Code chuẩn hoá thì mình mượn của 1 bác ở trong diễn đàn, tại vì lên google search thấy code bác ấy hiện ra luôn nên mượn. [IMG]images/smilies/2.gif[/IMG] Bác thông cảm nhé. Mình viết code bằng Visual Studio 2010, chạy F5 thì nó báo ko mở được file, còn chạy bằng cmd thì lại báo biến strWordOld chạy mà ko dc khai báo, mọi người xem giúp mình với. [IMG]images/smilies/tongue.png[/IMG]
Mã:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define distance 'a'-'A'
#define space 32
#define comma ','
#define dot '.'
#define colon ':'
#define question '?'
#define factorial '!'
#define semicolon ';'
#define ellipsis "..."

void main(int argc, char* argv[])
{
	if (argc == 3)
	{
	FILE* fp = fopen(argv[1], "rt");
	if (fp != NULL)
	{
		int k = ftell(fp), i = 0, len = 0, iFlag = 0;
		char** strWordOld, **strWordNew;
		char strCheck[] = "x", strFix[] = "x";
		*strWordOld = (char*)malloc(k*sizeof(char));
		*strWordNew = (char*)malloc(k*sizeof(char));
		while (feof(fp) == 0)
		{
			fscanf(fp, "%c", &strCheck);
			if(strcmp(strCheck," ") == 0)
			{
				continue;
			}
			else
			{
				fscanf(fp, "%[^ ]", strWordOld[i]);
				i++;
			}
		}
		for (int j = 1; j <= i; j++)
		{
			len = strlen(strWordOld[j]);
			strlwr(strWordOld[j]);
			strcpy(strWordOld[j], strFix);
			if (isellipsis(strWordOld[j]) == 1)
			{
				*strWordNew[j - 1] += *strWordOld[j];
				continue;
			}
			if (j == 1 && islower(strFix[0]) == 1)
			{
				strFix[0] = strFix[0] - 32;
				continue;
			}
			if (iFlag == 1)
			{
				strFix[0] = strFix[0] - 32;
				iFlag == 0;
				continue;
			}
			if(len == 1 && isspecialchr(strFix[0]) == 1)
			{
				*strWordNew[j-1] = *strWordNew[j-1] + strFix[0];
				iFlag = ispunctuation(strFix[0]);
			}
		}
		FILE* fpo = fopen(argv[2], "wt");
		for ( int j = 1; j <= i; j++)
		{
			fprintf(fpo,"%s ", strWordNew[j]);
		}
		fclose(fpo);
	}
	else
	{
		printf("Khong mo duoc file!
");
	}
	fclose(fp);
	}
	else
	{
		printf("Khong chay dc, cdkm");
	}
}

int isspecialchr(char ch)
{
    return  ch == comma || ch == dot || ch == colon ||
            ch == question || ch == factorial || ch == semicolon;
}

int nonupper(char ch)
{
    return  ch == comma || ch == semicolon;
}

int islower(char ch)
{
    return  'a' <= ch && ch <= 'z';
}

void append(char *sptr, char * &dptr)
{
    *dptr = *sptr;
    dptr ++;
}

int isellipsis(char *s)
{
    return  *s == dot && *(s+1) == dot && *(s+2) == dot;
}

int ispunctuation(char ch)
{
    return ch == dot || ch == question || ch == factorial;
}
Bài tập sắp phải nộp rồi, mọi người giúp mình với nhé. Thanks [IMG]images/smilies/kiss.gif[/IMG]