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 time I have a big problem (for me) with C language.
I searched in cplusplus.com or in google, and I tried with each function
but I don't solve this following question.
I have a text file with six rows, for example:
# begin file
row1...
row2...
# end file
I want to scan this file in C (not C++) language with stream and string functions.
ref Stream question, good so there is no confusion then.
Quote:
Originally Posted by shifter
I think this is a forum where someone can post questions.
Sure you can post questions but if someone answers it is another matter, so you have to help people to help yourself. "I tried with each function" What did you try? what did not work? what is your actual problem?
You still have not told us of the problem (although we can see it) and you failed once again to answer the question
Quote:
Once again is this homework or not?
Does this code compile? what error does it give?
What are the parameters types for the function getline?
How big is the string which you have allocated for the line?
What is the result of fopen?
What is the return value of getline?
You should try upping you warning level and this will give you a hint as to why you are having a problem. In short the function is a GNU extension and not an ansi function and a warning will tell you something like "implict function declaration". Add the following to your code before including stdio.h
and then think about the questions I already posed.
Quote:
Does this code compile? what error(edit: or warnings [why they are warnings without casts I do not know]) does it give?
What are the parameters types for the function getline?
How big is the string which you have allocated for the line?
What is the result of fopen?
What is the return value of getline?
It may seem to you that I am being a pedantic arse, but hopefully this thread has shown you how you ask a question correctly and therefore get answers which may help you. In addition how you could possibly find the solution for yourself in future.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.