Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char ** read_text(char buf[], char * addr[], int size_buf, int size_addr) {
- int lines_read = 0, c, i;
- char line[size_buf];
- while (lines_read < size_addr) { // read while there is space
- addr[lines_read] = malloc(size_buf);
- for (; i < size_buf && ( (c = getchar()) != '\n'); i++ ) { // put character in buffer
- buf[i] = c;
- }
- buf[i] = '\0'; i = 0;
- addr[lines_read] = realloc (buf, size_buf);
- lines_read += 1;
- }
- return addr;
- }
- int main() {
- char buf[10]; // x chars.
- char * addr[5]; // 5 lines;
- read_text(buf, addr, 10, 5);
- printf("%s\n", addr[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement