From your comment:
I am observing the garbage characters inside Visual Studio IDE while debugging. I am using VS6.0.
OK so I think it is a problem about character sets. As Andrew said it, your text file is probably not a Unicode text file and since your computer is not french you can't display the characters properly. (Visual Studio will take the current locale settings and load the corresponding characters set for the 8-bits characters).
I suggest that you convert your input string into unicode strings using these functions:
#define MAX_SIZE 1000
#define CODE_PAGE 1250
WCHAR* AnsiToUnicode(LPCSTR ansiString)
{
static WCHAR unicodeString[MAX_SIZE];
MultiByteToWideChar(
CODE_PAGE,
MB_PRECOMPOSED,
ansiString,
-1,
unicodeString,
MAX_SIZE
);
return unicodeString;
}
char* UnicodeToAnsi(LPCWSTR unicodeString)
{
static char ansiString[MAX_SIZE];
WideCharToMultiByte(
CODE_PAGE,
0,
unicodeString,
-1,
ansiString,
MAX_SIZE,
NULL,
NULL
);
return ansiString;
}
void test()
{
FILE *fp;
char str[100];
fp = _tfopen(_T("D:\\myfile.csv"), _T("rt"));
while (fgets(str, 100, fp))
{
WCHAR* wstr = AnsiToUnicode(str);
}
}
Or you may use cleaner versions of these functions:
int AnsiToUnicode(LPCSTR ansiString, LPWSTR unicodeString, int maxSize)
{
return MultiByteToWideChar(
CODE_PAGE,
MB_PRECOMPOSED,
ansiString,
-1,
unicodeString,
maxSize
);
}
int UnicodeToAnsi(LPCWSTR unicodeString, char* ansiString, int maxSize)
{
return WideCharToMultiByte(
CODE_PAGE,
0,
unicodeString,
-1,
ansiString,
maxSize,
NULL,
NULL
);
}
And don't forget to enable unicode string display under Visual Studio:
To set your debugger options to display Unicode strings, click the Tools menu, click Options, click Debug, then check the Display Unicode Strings check box.