Hi everyone:
I'm reading a file (line by line) but what I wanna do is to jump some lines, but I can't really figure out how to do that. I hope someone can help me out.

It is not normally possible to just skip lines in a text file. Just read the file from beginning to end until you get to the line you want. If this is going to be done frequently on a file that rarly, if ever, changes then there are some techinquest to index the file for quicker access, but I doubt this is what you will want to do anytime soon.

Thanks. But I was wondering if there was a way to skip lines in C. I'd appreciate if you could tell me whether that is possible or not. If your answer is the former, plz tell me how. Thanks in advance.

>>But I was wondering if there was a way to skip lines in C
I already answered that question. please re-read my previous post. If you did not understand my answer then ask about the part you did not understand.

do a google for "c++ tutorial" "File I/O" i remember doinh it about 8 months ago, theres a great free one that tells you just how to do that

I wonder if OP means he is reading some source code with his physical eyes, and wants to know what the equivalent of BASIC's goto is. If so, its:

go label

line 1
line 2
line 3

label:

Or, if you are reading a file, and you want to know how to spot the end of a line, look for a 0xA character.

At least I think it's "go"; I so seldom use it I'm not sure. It may be "goto".

Member Avatar for iamthwee

I wonder if OP means he is reading some source code with his physical eyes

I don't know, he could be using his glass eyes?

Reading a file in properly in c is quite trickly. There's lots of gotchas to avoid.

I always consult the bible.

http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046476070&id=1043284351

It's the last snippnet you need btw.

All you gotta do is put each line in a 2D char array and then point to which ever one you gotta skip to.
If you're stuck on this part ask and someone will show you how.

Member Avatar for iamthwee

As any veteran could tell

I'm not a veteran, but I always wanted to work with sick animals.

As any veteran could tell you, the real "bible" for C programmers was "K & R" (abbreviation), published many years ago by Prentice Hall.

...which has a lot of typo errors.

The link which Mr. Iamthwee pointed out is referred by thousands of people everyday( through Googlegroups, Daniweb or any other forum ). Have you ever seen anyone link to K & R ? But I have seen a lot of posts linking to the above link or some other good pages.

Its not that it is not a good book but the typos there can be fatal to newbies. Once the basics are cleared no harm in referring the book thought there are better online manuals.....

Have you ever seen anyone link to K & R ?

Well it's still available in print, so if somebody suggested to Prentice Hall that they might like to make it available for free on line, I suppose they might think that they had heard of better ideas.

Well it's still available in print, so if somebody suggested to Prentice Hall that they might like to make it available for free on line, I suppose they might think that they had heard of better ideas.

Maybe I should have been more specific, by link I meant recommend. But one thing which is true is it has typos and that I am sure of.

Quite frankly I have never read K&R. I looked at it briefly in a local book store, saw the size and price, then decided to buy a book that was 3 times its size and half its price. Some people live and breath K&R, but I think it is a waste of money, especially for beginniners. As for errors, almost every book has those. One would think that for the price the publishers demand for those books they would have better reviewers to catch programming errors.

but I think it is a waste of money, especially for beginniners.

Odd. K & R is how I got started in C. There were plenty of diabolical introductory texts around at the time, and they did everything they could to justify C's reputation as a difficult language to learn, but K & R wasn't one of them.

It wasn't for no reason that, prior to the publication of ansi C, the letters K & R were to be seen plastered around all over the place.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.