programming problem....C programming..not sure whether this can be done or not
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.
hey all,
i am trying to solve this problem for quite sometimes..hopefully some here can help me.....i even used the codes here to try and program...but somehow when i put other codes it give me problems.I used another program to create another text file and the mode is appending(fopen("text.txt","a")). i am trying to read this text file line by line and using function strtok i split the string line by line into 2 string...i include here both of my c programs,the text.txt, and the outputs after executing the programs.....
Please help me...im trying to solve this problem for quite sometimes and still couldnt manage to solve it...thanks in advanced
could u help me with explanation...i still couldnt really understand ur codes...
i couldnt understand ur code from char **lines=NULL; till lines[nlines++]=stdup(line);....thanks in advanced..anyways u really help me out..thanks mate
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
nikhidet1, you've been asked several times to put your code between [code] and [/code]. This means to put [code] before the start of your code and [/code] after the end of your code. Please do this to preserve indentation and aid readability.
yeah i refer to you NevemTeve.i got one thing to ask.why u choose to times nmaxlines with two and if the condition is not true why u choose to have nmaxlines is equal to 64?i am referring to line (nmaxlines= nmaxlines? 2*nmaxlines: 64..is there any specific reason?can i times the nmaxlines with 3 instead of 2 and can i replace 64 with other value....thanks in advanced...
The only important thing is not to call realloc to often (waste of CPU). For start, allocating 64 pointers takes 256/512 bytes, which is almost nothing. Later, when we run out of space, we double the allocated memory -- it seems to be an overkill, but still, any given time less than the half of the memory is unused.
And, if we really want, after reading in the whole file, we can release the unused area with another realloc:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.