M
MIUSS
Hello everyone!
I got a problem with creating new line...
I tried this: lstrcpy(NewLineIdr, TEXT("\r\n"));
I already tried this: NewLineIdr[0] = 0x000D; NewLineIdr[1] =
0x000A; NewLineIdr[2] = 0x0000;
I need it to use it in my saving procedure because I need to create
tabullary text file. But my effort usually results in one or two small
rectangles meaning probably unknown characters...
More interesting is one thing:
This is a part of my first func providing saving to file with new
line. It works well:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
lstrcpy(NewLine, TEXT("\r\n")); lstrcpy(Space, TEXT(" "));
lstrcpy(ParC[0], TEXT("ID: ")); lstrcpy(ParC[1],
TEXT("Datum: ")); lstrcpy(ParC[2], TEXT("ID_zakazky"));
lstrcpy(ParC[3], TEXT("PocetHodin")); lstrcpy(ParC[4],
TEXT("Popis "));
lpString = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, ((5*10)/*Polozky*/
+(4*3)/*Mezery*/+3+2 +40/*delka popisku*/)*sizeof(TCHAR));
Buf[0] = 0xFEFF; Buf[1] = 0x0000; // First two TCHARS informing
that file uses UNICODE
lstrcpy(lpString, Buf); // Copies unicode-inform-TCHARs to
initiation of string
for(a=0;a<5;a++){ // Copies adapted ParCS strings to
lpString pointer
lstrcat(lpString, ParC[a]);
if(a!=4) lstrcat(lpString, Space);
}
for(a=0;a<4;a++) lstrcat(lpString, TEXT("Popis "));
lstrcat(lpString, NewLine);
hSoubor = CreateFile(szSoubor, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
0, NULL);
if(hSoubor == INVALID_HANDLE_VALUE){
HeapFree(GetProcessHeap(), 0, lpString);
MessageBox(g_hWnd, TEXT("An error in writing file occured. Save
failed!"), TEXT("Read/Write file error"), MB_ICONERROR);
return;
}
if(!WriteFile(hSoubor, lpString, (((5*10)/*Polozky*/+(4*3)/*Mezery*/+
40/*delka popisku*/ +3)*sizeof(TCHAR)), &dwZapsano, NULL)){
MessageBox(g_hWnd, TEXT("An error in writing file occured. Save
failed!"), TEXT("Read/Write file error"), MB_ICONERROR);
}
return;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
And this is a part of my second func that should save to text file
with new lines:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GetWindowText(hWndID, PolozkaProZapis[0], 11);
GetWindowText(hWndDatum, PolozkaProZapis[1], 11);
GetWindowText(hWndIDzakazky, PolozkaProZapis[2], 11);
GetWindowText(hWndPocetHodin, PolozkaProZapis[3], 11);
GetWindowText(hWndPopis, PolozkaProZapis[4], 51);
lstrcpy(Space, TEXT(" "));
DelkaStr=lstrlen(PolozkaProZapis[4]);
for(a=0;a<(50-DelkaStr);a++) PolozkaProZapis[4][a+DelkaStr] = 0x0020;
PolozkaProZapis[4][49] = 0x0000;
for(a=0;a<4;a++){
DelkaStr = lstrlen(PolozkaProZapis[a]);
for(b=0;b<DelkaStr;b++){
TempPolozka[b+(10-DelkaStr)] = PolozkaProZapis[a];
}
for(b=0;b<(10-DelkaStr);b++){
TempPolozka = 0x0020;
}
TempPolozka[10]=0x0000;
lstrcpy(PolozkaProZapis[a], TempPolozka);
}
lstrcpy(Line, TEXT(""));
for(a=0;a<5;a++){ lstrcat(Line, PolozkaProZapis[a]); lstrcat(Line,
Space);}
lstrcpy(NewLineIdr, TEXT("\r\n")); //NewLineIdr[0] = 0x000D;
NewLineIdr[1] = 0x000A; NewLineIdr[2] = 0x0000;
lstrcat(Line, NewLineIdr);lstrcat(Line, TEXT(""));
DelkaLinky = lstrlen(Line);
if((stream = _wfopen(szSoubor, L"a")) != NULL){
nw = fwrite(&Line, sizeof(TCHAR), DelkaLinky, stream);
}
fclose(stream);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I use almost the same way to add new line to string, but when I use
fwrite instead of writefile I get two rectangles instead of lines when
I look to saved file in notepad.... How is it possible?
Any help will be appreciated...
Have a nice day.
I got a problem with creating new line...
I tried this: lstrcpy(NewLineIdr, TEXT("\r\n"));
I already tried this: NewLineIdr[0] = 0x000D; NewLineIdr[1] =
0x000A; NewLineIdr[2] = 0x0000;
I need it to use it in my saving procedure because I need to create
tabullary text file. But my effort usually results in one or two small
rectangles meaning probably unknown characters...
More interesting is one thing:
This is a part of my first func providing saving to file with new
line. It works well:
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
lstrcpy(NewLine, TEXT("\r\n")); lstrcpy(Space, TEXT(" "));
lstrcpy(ParC[0], TEXT("ID: ")); lstrcpy(ParC[1],
TEXT("Datum: ")); lstrcpy(ParC[2], TEXT("ID_zakazky"));
lstrcpy(ParC[3], TEXT("PocetHodin")); lstrcpy(ParC[4],
TEXT("Popis "));
lpString = (LPTSTR)HeapAlloc(GetProcessHeap(), 0, ((5*10)/*Polozky*/
+(4*3)/*Mezery*/+3+2 +40/*delka popisku*/)*sizeof(TCHAR));
Buf[0] = 0xFEFF; Buf[1] = 0x0000; // First two TCHARS informing
that file uses UNICODE
lstrcpy(lpString, Buf); // Copies unicode-inform-TCHARs to
initiation of string
for(a=0;a<5;a++){ // Copies adapted ParCS strings to
lpString pointer
lstrcat(lpString, ParC[a]);
if(a!=4) lstrcat(lpString, Space);
}
for(a=0;a<4;a++) lstrcat(lpString, TEXT("Popis "));
lstrcat(lpString, NewLine);
hSoubor = CreateFile(szSoubor, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
0, NULL);
if(hSoubor == INVALID_HANDLE_VALUE){
HeapFree(GetProcessHeap(), 0, lpString);
MessageBox(g_hWnd, TEXT("An error in writing file occured. Save
failed!"), TEXT("Read/Write file error"), MB_ICONERROR);
return;
}
if(!WriteFile(hSoubor, lpString, (((5*10)/*Polozky*/+(4*3)/*Mezery*/+
40/*delka popisku*/ +3)*sizeof(TCHAR)), &dwZapsano, NULL)){
MessageBox(g_hWnd, TEXT("An error in writing file occured. Save
failed!"), TEXT("Read/Write file error"), MB_ICONERROR);
}
return;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
And this is a part of my second func that should save to text file
with new lines:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
GetWindowText(hWndID, PolozkaProZapis[0], 11);
GetWindowText(hWndDatum, PolozkaProZapis[1], 11);
GetWindowText(hWndIDzakazky, PolozkaProZapis[2], 11);
GetWindowText(hWndPocetHodin, PolozkaProZapis[3], 11);
GetWindowText(hWndPopis, PolozkaProZapis[4], 51);
lstrcpy(Space, TEXT(" "));
DelkaStr=lstrlen(PolozkaProZapis[4]);
for(a=0;a<(50-DelkaStr);a++) PolozkaProZapis[4][a+DelkaStr] = 0x0020;
PolozkaProZapis[4][49] = 0x0000;
for(a=0;a<4;a++){
DelkaStr = lstrlen(PolozkaProZapis[a]);
for(b=0;b<DelkaStr;b++){
TempPolozka[b+(10-DelkaStr)] = PolozkaProZapis[a];
}
for(b=0;b<(10-DelkaStr);b++){
TempPolozka = 0x0020;
}
TempPolozka[10]=0x0000;
lstrcpy(PolozkaProZapis[a], TempPolozka);
}
lstrcpy(Line, TEXT(""));
for(a=0;a<5;a++){ lstrcat(Line, PolozkaProZapis[a]); lstrcat(Line,
Space);}
lstrcpy(NewLineIdr, TEXT("\r\n")); //NewLineIdr[0] = 0x000D;
NewLineIdr[1] = 0x000A; NewLineIdr[2] = 0x0000;
lstrcat(Line, NewLineIdr);lstrcat(Line, TEXT(""));
DelkaLinky = lstrlen(Line);
if((stream = _wfopen(szSoubor, L"a")) != NULL){
nw = fwrite(&Line, sizeof(TCHAR), DelkaLinky, stream);
}
fclose(stream);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I use almost the same way to add new line to string, but when I use
fwrite instead of writefile I get two rectangles instead of lines when
I look to saved file in notepad.... How is it possible?
Any help will be appreciated...
Have a nice day.