c 파일 입출력 관련 질문 드립니다

에코 클라이언트에 입력한 모든 데이터를 txt 파일에 저장하려고 하는데 막혔습니다 텍스트 파일 생성 은 되지만 마지막에 입력한 글자만 입력이 됩니다(종료하려면 q 눌려야해서 q만 입력됨) 입력한 모든 걸 집어넣는 건 어떻게 하나요?


코드

#include "MySocket.h"
int main(void)
{

	printf("+++++++++++++++++++++++++++\n");
	printf("Echo Server ver1.0\n");
	printf("Written by nobody,Oct.31,2019 \n");
	printf("+++++++++++++++++++++++++++\n");

	int errorCode = -1234; //초기화 initialize



	//WSAStartup
	WSADATA wd = { 0, };
	errorCode=WSAStartup(MAKEWORD(2, 2), &wd);
	if (errorCode)
		ErrorDisplay("WSAStartup");
	else OK("WSAStartup");

	//socket - serverSocket making
	SOCKET serverSocket;
	serverSocket = socket(AF_INET, SOCK_STREAM, 0);
	if (serverSocket == INVALID_SOCKET)
		ErrorExit("socket");
	else OK("socket");
	//bind - SERVER IP/PORT bind
	SOCKADDR_IN serverAddress = { 0, };
	wchar_t server_IPPort[] = SERVER_IPPORT;
	int sizeServerAddress = sizeof(serverAddress);
	errorCode=WSAStringToAddressW(server_IPPort,
		AF_INET, NULL,
		(SOCKADDR*)&serverAddress,
		&sizeServerAddress);
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("WSAStringToAddressW");
	else OK("WSAStringToAddressW");

	errorCode=bind(serverSocket, (SOCKADDR*)&serverAddress,
		sizeof(serverAddress));
	if(errorCode==SOCKET_ERROR)
		ErrorDisplay("bind");
	else OK("bind");

	//listen - client listening
	errorCode=listen(serverSocket, 5);
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("listen");
	else OK("listen");

	//accept - clientSocket making through serverSocket
	SOCKET clientSocket;
	SOCKADDR_IN clientAddress = { 0, };
	int sizeClientAddress = sizeof(clientAddress);
	clientSocket = accept(serverSocket,
		(SOCKADDR*)&clientAddress, &sizeClientAddress);
	if (clientSocket == INVALID_SOCKET)
		ErrorDisplay("accept");
	else OK("accept");

	wchar_t clientIPPort[32] = { 0, };
	DWORD sizeClientIPPort = sizeof(clientIPPort);
	errorCode=WSAAddressToStringW((SOCKADDR*)&clientAddress,
		sizeof(clientAddress), NULL,
		clientIPPort, &sizeClientIPPort);
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("WSAAddressToStringW");
	else OK("WSAAddressToStringW");

	wprintf(L"client accepted(%s)\n", clientIPPort);
	//recv/send - data transmit
	char buffer[BUF_SIZE] = { 0, };

	FILE *in = 0;
	fopen_s(&in, "1Copy.txt.", "w");




	if (in == NULL) {
		printf(" 생성 실패 \n");

	}

//	int errorCode = -1;
	while (-23)
	{

		
		errorCode=recv(clientSocket, buffer, BUF_SIZE, 0);
		
		//if(errorCode==0)
		if (!errorCode)
		{
			printf("client closed\n");
			break;
		}
		else if (errorCode == SOCKET_ERROR)
		{
			ErrorDisplay("recv");
		}
		else OK("recv");
		errorCode=send(clientSocket, buffer, BUF_SIZE, 0);
		if (errorCode == SOCKET_ERROR)
			ErrorDisplay("send");
		else OK("Send");

	
	}
	//closesocket - clientSocket
	errorCode=closesocket(clientSocket);
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("closesocket-client");
	else OK("closesocket-client");
	//closesocket - serverSocket
	errorCode=closesocket(serverSocket);
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("closesocket-server");
	else OK("closesocket-server");

	//WSACleanup
	errorCode=WSACleanup();
	if (errorCode == SOCKET_ERROR)
		ErrorDisplay("WSACleanup");
	else OK("WSACleanup");

	fputs(buffer, in);

	fclose(in);
	getchar();
	return 0;

}

안녕하세요~~

fput 함수가 마지막에만 있죠?
입력하는 모든걸 저장하고 싶으면 어떻게해야할까요?

입력할때마다 fput 함수를 불러다가 buffer를 in에 저장하면 되겠지요?? ^^/
q가 저장되기 싫으면요??
q를 입력했는지 조건을 걸어서 저장안하고 종료하면 되겠죠?

어쩌피 q를 입력하면 종료한다고 하셨으니 그 조건문은 있을테니까용 ㅎㅎㅎ

답변 감사합니당 ㅎㅎ