#include <stdio.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#endif
void createFile(const char *filename) {
#ifdef _WIN32
HANDLE hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile != INVALID_HANDLE_VALUE) {
CloseHandle(hFile);
printf("File created successfully on Windows.\n");
} else {
printf("Failed to create file on Windows.\n");
}
#else
int fd = open(filename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd != -1) {
close(fd);
printf("File created successfully on Linux.\n");
} else {
printf("Failed to create file on Linux.\n");
}
#endif
}
int main() {
createFile("test.txt");
return 0;
}