ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
this is probably a stupid questions but what data type is used for pointers?
what i want to do is set up a structure that (at one of its members) will hold various pointers to other structures, which will also hold pointers to lines of text, taken from getline() (using dynamic allocation for the memory thing)
also does anyone know what size is for dynamic allocation?, getline wants me to input the size of the buffer, but since its supposed to change itself I'm not sure if there is a size..?, or should i just use sizeof() to get the size it asks for?
I assume that's kind of what you're talking about anyway...
As for size during dynamic allocation. You tell malloc() how much memory to allocate so you should already know the size. You don't want to use sizeof() on a pointer to allocated memory because you'll only get the size of the pointer (e.g. 'char *ptr = malloc(10); printf("%d\n", sizeof(ptr));' will show 4, not 10 like you might expect). But if you have something like 'char buf[10]; printf("%d\n", sizeof(buf));' then it will show 10.
right, umm, i don't know the full size of the line, but it cant be bigger then a unsigned int , so i guess ill just tell it to do that .. but also the size of the line will change when its laoded..
hmm, does anyone think it will be better to let getline() make its own buffer, then copy its contents into a dynamic buffer?
and thx for the help with the structures, i think it should work with arrays since thats what i think ill be using to keep track of the other structures as they should be changing a lot
size_t bufsiz = 0;
ssize_t linelen;
char* line = NULL;
while ((linelen = getline(&line, &bufsiz, infile)) != -1) {
printf("Got a line length %d. Here is the line:\n%s", linelen, line);
}
free(line);
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.