[Dev-C++] Possible bug? (fdopen and fgets)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Tracid <tr...@za...> - 2006-01-02 14:05:02
|
Hello.
I've got a little problem. If I use the fdopen function, and then I use
fgets, the compiled program crashes*.
Example:
#include <stdio.h>
#include <winsock.h>
#include <windows.h>
#pragma comment (lib, "ws2_32")
int main(int argc, char *argv[])
{
WSADATA wsaData;
if (WSAStartup (MAKEWORD(1, 1), &wsaData) != 0) {
printf ("[-] WSAStartup failed.\n");
return (1);
}
int sockfd;
char buf[1024];
FILE *in;
/* some stuff here, connection to server is successfull */
in = fdopen (sockfd, "r"); /* in
while (fgets(buf, sizeof(buf), in) != NULL) { /* and here the
compiled program crashes* */
/* some other stuff */
------------------
Using cygwin, it works well.
*Crashes = Windows error reporting window appears, and program ends
suddenly.
Is this problem caused by Dev-Cpp or the Windows sockets?
Thank you.
PS: I admit that I am quite a newbie at C programming, but I've tried a
lot of different variations for this, but it still crashes....
|