fork download
  1. #include <fcntl.h> // For open()
  2. #include <unistd.h> // For read() and close()
  3. #include <stdio.h> // For printf()
  4.  
  5. int main() {
  6. int a = open("test.txt", O_RDONLY); // Open "test.txt" in read-only mode
  7. char b[11]; // Declare a character array of size 11
  8. read(a, b, 10); // Read up to 10 characters from the file into b
  9. b[10] = '\0'; // Add null terminator at the end of the string
  10. printf("%s", b); // Print the contents of b
  11. close(a); // Close the file
  12. return 0;
  13. }
  14.  
Success #stdin #stdout 0s 5288KB
stdin
10000
stdout
Standard output is empty