What's new

Closed Getline and putline in c

Status
Not open for further replies.

Captain_Steve

Eternal Poster
Joined
Jun 3, 2018
Posts
1,024
Reaction
343
Points
400
meron po ba jan mga master mag program? di ko po kasi ma run program ko, using getline() and putline() function nasa user defined header po yan, tama naman po pagka include ko, kasi lagi po nasa error ko undefined reference getline()... pag na call ko sya sa main function ko po.

eto po yung function ko para sa sa getline and outline

nasa loob po ito ng inout.h na header
int getline(char *line, int max);
void putline(char *line);
 
Ano compiler mo? POSIX-compliant? Meron ng getline(), but not putline(). Were you trying to reinvent them? Sounds like a bad idea.

Yung getline mo says:

int getline(char *line, int max);

pero as per 'man page', dapat yung 1st argument is an array of strings, ie char ** versus yung sayo na string lang. Saka yung return value is ssize_t vs int yung sayo.

Eto as per man page:

Code:
GETLINE(3)                                                                 Linux Programmer's Manual                                                                 GETLINE(3)

NAME
       getline, getdelim - delimited string input

SYNOPSIS
       #include <stdio.h>

       ssize_t getline(char **lineptr, size_t *n, FILE *stream);

       ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       getline(), getdelim():
           Since glibc 2.10:
               _POSIX_C_SOURCE >= 200809L
           Before glibc 2.10:
               _GNU_SOURCE
...

Eto sample code ko using getline()

Code:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char *mystring = NULL;
    size_t nbytes = 10;
    printf("Enter string: ");
    getline(&mystring, &nbytes, stdin);
    printf("You entered:  %s\n", mystring);
    free(mystring);
    return 0;
}

Hope this helps.

BTW, hindi pa ko master and am still learning.
 
Last edited:
maramkng
Ano compiler mo? POSIX-compliant? Meron ng getline(), but not putline(). Were you trying to reinvent them? Sounds like a bad idea.

Yung getline mo says:

int getline(char *line, int max);

pero as per 'man page', dapat yung 1st argument is an array of strings, ie char ** versus yung sayo na string lang. Saka yung return value is ssize_t vs int yung sayo.

Eto as per man page:

Code:
GETLINE(3)                                                                 Linux Programmer's Manual                                                                 GETLINE(3)

NAME
       getline, getdelim - delimited string input

SYNOPSIS
       #include <stdio.h>

       ssize_t getline(char **lineptr, size_t *n, FILE *stream);

       ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream);

   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

       getline(), getdelim():
           Since glibc 2.10:
               _POSIX_C_SOURCE >= 200809L
           Before glibc 2.10:
               _GNU_SOURCE
...

Eto sample code ko using getline()

Code:
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char *mystring = NULL;
    size_t nbytes = 10;
    printf("Enter string: ");
    getline(&mystring, &nbytes, stdin);
    printf("You entered:  %s\n", mystring);
    free(mystring);
    return 0;
}

Hope this helps.

BTW, hindi pa ko master and am still learning.
maraming salamat po, nagka idea po ako :) nag ddownload po ba ang posix?
 
Status
Not open for further replies.

Similar threads

Back
Top