Skip to content

Instantly share code, notes, and snippets.

@FedericoPonzi
FedericoPonzi / socket_portable.c
Last active June 16, 2025 21:34
C sockets portable in windows/linux example
// As seen on http://www.di.uniba.it/~reti/LabProRete/Interazione(TCP)Client-Server_Portabile.pdf
#if defined WIN32
#include <winsock.h>
#else
#define closesocket close
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <stdio.h>
@FedericoPonzi
FedericoPonzi / win32api-create-and-write.c
Created October 17, 2014 13:46
Create and write inside a file using the Win32api in C.
#include <windows.h>
#include <stdio.h>
int main(int argc, CHAR *argv[])
{
HANDLE hFile;
char DataBuffer[] = "This ia s test string to be written.";
DWORD dwBytesToWrite = (DWORD) strlen(DataBuffer);
DWORD dwBytesWritten = 0;
@FedericoPonzi
FedericoPonzi / win32api-simplels.c
Last active August 29, 2015 14:07
This is a simple ls version using the win32api.
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <direct.h>
int main(int argc, char **argv)
{
HANDLE handleFind;
WIN32_FIND_DATA findFileData;
char *dir;
@FedericoPonzi
FedericoPonzi / win32api-reverse.c
Last active August 29, 2015 14:07
File reverser usando le win32api
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
char s; //buffer
HANDLE file; //Handle del file
@FedericoPonzi
FedericoPonzi / FileReverse.c
Last active August 29, 2015 14:07
Reverse in c.
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char **argv )
{
FILE *in_file;
char ch;
int len;