(C++) fgets kann nich mehr als 7kbs?
-
Hallo! Wenn ich folgende Anwendung mit einer Datei, größer als ca. 7kb durchlaufen lasse schmiert mir die Anwendung ab! Als Begründung erhalte ich str != NULL in der Datei fgets.h oda cpp weiß nich genau jetzt!
Woran kann das liegen?
Hier der Code:#include "windows.h" #include "stdio.h" #include "iostream.h" void DelZeile(); int ReadLine(char *buffer,int iZeile, char *pfad); BOOL FindChar(char *szText, char *szFind); static char Zeile[1024]; LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void Schreiben(char * text, char * pfad, int iLaenge); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, int nShowCmd) { HWND hWnd; MSG msg; WNDCLASS wc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursor(0, IDC_ARROW); wc.hInstance = hInstance; wc.lpfnWndProc = WndProc; wc.lpszClassName = "FarbFinder"; wc.lpszMenuName = 0; wc.style = CS_VREDRAW | CS_HREDRAW; RegisterClass(&wc); hWnd = CreateWindow("FarbFinder", "FarbFinder 1.0", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 500, 0,0, hInstance, 0); ShowWindow(hWnd, nShowCmd); UpdateWindow(hWnd); while(GetMessage(&msg, 0,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hDC; static HWND hPath, hButton; static char szPath[MAX_PATH]; static char szIPs[500000]; static FILE *file; static int iLine = 0; static int iIIS = 0; switch(message) { case WM_COMMAND: switch(wParam) { case 0: GetWindowText(hPath, szPath, MAX_PATH); file = fopen(szPath, "r"); if(file) { iLine = 0; iIIS = 0; for(BOOL bBool = TRUE; bBool == TRUE;) { DelZeile(); if(!(fgets(Zeile, MAX_PATH, file))) { MessageBox(0, "Ende", 0, 0); break; bBool = FALSE; } if(FindChar(Zeile, "195")) { ReadLine(Zeile, iLine, szPath); strcat(szIPs, Zeile); } iLine++; } Schreiben(szIPs,"c:\\test23.txt",strlen(szIPs)); } else { MessageBox(0, "nicht geöffnet worden" ,0, 0); } break; } break; case WM_CREATE: hPath = CreateWindow("edit", "Pfad", WS_VISIBLE | WS_BORDER | WS_CHILD, 50, 50, 400, 20, hWnd, 0, 0, 0); hButton = CreateWindow("button", "Überprüfe", WS_VISIBLE | WS_BORDER | WS_CHILD, 200, 100, 80, 30, hWnd, 0, 0, 0); break; case WM_DESTROY: PostQuitMessage(0); return 0; break; } return DefWindowProc(hWnd, message, wParam, lParam); } void DelZeile() { for(int i = 0; i < strlen(Zeile); i++) { Zeile[i] = NULL; } } void Schreiben(char * text, char * pfad, int iLaenge) { HANDLE hFile; DeleteFile(pfad); hFile = CreateFile(pfad, GENERIC_READ | GENERIC_WRITE , NULL, NULL, CREATE_NEW, NULL, NULL); DWORD geschrieben; WriteFile(hFile, text, iLaenge, &geschrieben, 0); CloseHandle(hFile); } BOOL FindChar(char *szText, char *szFind) { for(int i = 0; i < strlen(szText); i++) { if(szText[i] == szFind[0]) { if(szText[i + 1] == szFind[1]) { if(szText[i + 2] == szFind[2]) { return TRUE; } } } } return FALSE; } int ReadLine(char *buffer,int iZeile, char *pfad) { FILE *datei; datei = fopen(pfad, "r"); char text[1024]; for(int i = 0; i < iZeile; i++) { fgets(text, 1024, datei); } fgets(text,1024,datei); strcpy(buffer, text); return 0; }
Danke schonmal!!!
Kevin
-
Auch wenn es eine Windows-Anwendung ist, sind die entscheidenden Zeilen hier OT. Die Standard-C++ Profis sitzen im C++-Forum :D.
cya
EDIT: Sind windows.h, iostream.h (das man übrigens nicht mehr verwenden sollte, man sollte <iostream> nehmen) und stdio.h wirklich im Programmordner???
[ Dieser Beitrag wurde am 02.02.2003 um 12:15 Uhr von MagiC Creator editiert. ]
-
Stimmt, das hier gehört nach C++.
Warum benutzt du eigentlich <iostream> in einem WinAPI-Programm mit WinMain?
<iostream> ist doch für Konsolenein-/ausgabe da.
Wenn schon dann nimm <fstream>.fgets ist zwar C und kein C++, aber ich schiebe diesen Thread trotzdem nach C++; vielleicht kann man dich ja überreden fstream zu benutzen, da du eh schon iostream benutzt.