LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-28-2024, 07:25 PM   #1
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
How to tell what to do with a man page?


Maybe this is a moron question. I'm not sure. I'm finding that as I try to use various things in the C standard lib + a few others that it is a bit of trial and error to get them to work. This is an example of my biggest problem.

From the manpage for getline
Code:
       #include <stdio.h>

       ssize_t getline(char **restrict lineptr, size_t *restrict n,
                       FILE *restrict stream);
       ssize_t getdelim(char **restrict lineptr, size_t *restrict n,
                       int delim, FILE *restrict stream);
Yet this is the code that is needed to make it work. I wrapped it in a function for easy reuse.

Code:
char *
getline_stdin_mem_alloc(void)
{
  // declare & initialize
  size_t buflen = 0;
  char * buffer = NULL;
  if (getline(&buffer,
              &buflen,
              stdin) == -1) {
    free(buffer); buffer = NULL;
  }
  buffer[strcspn(buffer,
                 "\n")] = '\0';

  return(buffer);
}
So I suppose my question is how do I know when I'm supposed to target the address of the pointer verses passing a pointer. I'm worried this will be stupidly obvious and I'll slap my forehead when someone tells me but I just can't see it, short of trial and error anyway.

Code:
&ptr vs *ptr
??
 
Old 03-28-2024, 07:54 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,140

Rep: Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263Reputation: 1263
Pass ptr when you need the value of the pointer. Pass *ptr when you just need the value that it points to. Pass &ptr when you need to modify the pointer in the function.
 
1 members found this post helpful.
Old 03-28-2024, 09:00 PM   #3
jmgibson1981
Senior Member
 
Registered: Jun 2015
Location: Tucson, AZ USA
Distribution: Debian
Posts: 1,141

Original Poster
Rep: Reputation: 392Reputation: 392Reputation: 392Reputation: 392
Must have missed it. Pointers still mess with my head. Thank you very much for explaining that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sh is a symlink to bash but man sh shows man page of ksh M0M0 Slackware 15 02-23-2021 04:36 PM
What man page section would tell me about games? LINUXNEW08 Linux - Newbie 8 12-14-2013 09:41 PM
man page is not found although $MANPATH and man.conf changed Abbraxas Linux - Newbie 3 09-05-2011 06:40 PM
man alsamixer not showing the man page nosaku Slackware 1 12-20-2004 08:52 AM
Is there a man page on how to use man page? jdruin Linux - Software 2 10-30-2004 09:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration