forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_getline.c
More file actions
42 lines (34 loc) · 958 Bytes
/
test_getline.c
File metadata and controls
42 lines (34 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// Include our np_embed header
#include "Include/np_embed.h"
int main() {
// Test with a regular file first
FILE *test_file = fopen("test_input.txt", "w");
if (test_file) {
fprintf(test_file, "Line 1\nLine 2 with more text\nLine 3\n");
fclose(test_file);
}
// Test getline with our implementation
FILE *file = fopen("test_input.txt", "r");
if (!file) {
printf("Failed to open test file\n");
return 1;
}
char *line = NULL;
size_t len = 0;
ssize_t read;
int line_num = 1;
printf("Testing getline implementation:\n");
while ((read = getline(&line, &len, file)) != -1) {
printf("Line %d (length %zd): %s", line_num++, read, line);
}
free(line);
fclose(file);
// Clean up
unlink("test_input.txt");
printf("Test completed successfully!\n");
return 0;
}