Almost finished stdio.h

This commit is contained in:
2024-10-25 18:11:10 +02:00
parent 57bfddc65e
commit ad5bf2baab
6 changed files with 259 additions and 8 deletions
+32
View File
@@ -0,0 +1,32 @@
#include <stdio.h>
#include <stddef.h>
char* fgets(char* str, int n, FILE* stream) {
if (!str || !stream || n <= 1) { return NULL; }
char* dest = str;
int ch;
while (--n > 0 && (ch = getc(stream)) != EOF) {
*dest++ = ch;
if (ch == '\n') break; // Stop at newline
}
*dest = '\0'; // Null terminate
return (dest == str) ? NULL : str;
}
int fputs(const char* str, FILE* stream) {
if (!str || !stream) { return EOF; }
while (*str) {
if (putc(*str++, stream) == EOF) { return EOF; }
}
return 0;
}
inline char* gets(char* str, int n) { return fgets(str, n, stdin); }
inline int puts(const char* str) { return fputs(str, stdout); }