SunQuest
           C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #16  
Old May 6th, 2008, 03:54 PM
angel.white angel.white is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Location: Kansas
Posts: 17 angel.white User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 40 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by sizablegrin
We're trying to help people who need help, and who are willing to pay attention and get something useful from the responses.
I believe I qualify for all of these. When told the line ends were my problem, I wrote a script and tested the line ends. When told that I needed to use SEEK_SET I put my best effort into using SEEK_SET (could not get it to work, despite having 2 C books, and the power of google), when told to open it with "rb" I opened it with "rb" and tried the same approaches. When Scorpions explained to me how ungetc works, I realized what I was confused about regarding it, and was able to get that to work (what my code currently uses). And before I had anything working, after I had exhausted every method I could think of, and spent a good 4 hours trying in vain to determine if the next line is blank (something that should not be difficult) I thought of and implemented an alternative, a crappy alternative yes, but it did work. And even after I had this working code, I went back and revisited the topic after Scorpions post, and was able to get that previous method to work, and ended up replacing my string method with the ungetc method.

I spent about 6 hours on this process, the only hurdle was the question: "is the next line blank"

Perhaps my perspective is off, and such a question does require extensive amounts of time, and a mere 6 hours is nothing compared to what I should have put in. But based on the commonality such a question must surely possess, I strongly suspect this is not the case.

Quote:
Originally Posted by clifford
Maybe you will prefer C++. It is a better language with, (perhaps more importantly), a better library. Unfortunately for you that also means more choices - including bad ones - to be made.
I certainly hope so, I will be using C++ during the Fall. I am open to choices, more choices offer more methods around hurdles, and some are inevitably better than others, the concept of more efficient or more capable code is very appealing to me, and so more choices is preferable. Of course, with more choices comes more confusion, so I sincerely hope C++ is better documented than C.

Quote:
Originally Posted by clifford
My advice is not to do classes in stuff you dislike, and then get others to do the work for you. It seems you are likely to turn sizablegrin's work in as your own, without ever really understanding it. You will learn nothing, and the qualification you obtain will be devalued, which is particularly unfair on all those who obtained it honestly.
Well, the course is data structures and algorithms, and I do like data structures and algorithms, C is the language used to teach the course, so it is necessary to learn what I enjoy. Like most things in life, it is a balance. As for Sizablegrin's newline function, I do not use code that I do not understand, I will figure out how/why it works before I ever use it, otherwise when I encounter a problem, I will not know the source of the problem. I have had to create several standard library functions as a result of this (again, I cannot find standard library function's code documented despite looking for it, and asking my instructor). In regards to using his code, I do not expect he would provide it if he did not want me to use it. I have never understood the ownership of thoughts, perhaps someday in the future.

Quote:
Originally Posted by clifford
The point is assisting the enthusiastic who are willing to learn is rewarding. Assisting the lazy and disinterested is exhausting. This is presumably why your tutor, who's job it is, is not assisting you.
I do not know where you came up with this idea that I am lazy, I have tried everything suggested in this thread, I think you are merely put off by how much I hate C. If it helps, know that I do absolutely love data structures and algorithms, my best experiences in school this semester have been in this course. When my instructor told me I could not use a binary search on a linked list, and I worked every day for about 2 weeks until I got it to work, this last program was quite enjoyable, hash tables are the most interesting thing I have done with computers in quite a while. Earlier while working on Project Euler (which eventually led to my decision to abandon C) I wrote 3 programs to find prime numbers, and the idea behind the third one was the most complicated thing I had done up to that point, with somewhat abstract thought processes behind it (certainly the most abstract programming idea I've personally ever thought of)... I almost had an orgasm when it worked.

So I am sorry that my dislike for C puts you off, and I am sorry that you have gotten the impression that I am lazy, just know that I do thoroughly enjoy the concepts behind the code, and that my motivation is not hindered my that dislike.

Reply With Quote
  #17  
Old May 6th, 2008, 04:57 PM
sizablegrin's Avatar
sizablegrin sizablegrin is online now
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,066 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 14 h 15 m 29 sec
Reputation Power: 1445
Documentation is all over the web (and not hard to find). A decent compiler usually has it also.

If you would read the documentation for fgets you would discover that a newline, if present, is always at the end. Consequently, if you remove all \r and \n from the end of the string, and the string is then of zero length, you have a blank line.

There is little penalty in modern systems for using single-character reads, such as you attempted, simply because most modern systems read and cache the entire file (or as much as they can). In a lesser system such actions would incur a horrible penalty because file operations are orders of magnitude slower than memory accesses.

Tossing in seeks (particularly one- or two-character movements) where they are absolutely unnecessary is also a questionable decision.

There are algorithms and there are languages and there are the systems. With enough abstraction one can forget about the systems, but one will never be an optimal user if one does so.
Comments on this post
angel.white agrees: Thank you, it appears there is still quite a lot I need to figure out about files. -angel.white
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
  #18  
Old May 6th, 2008, 10:33 PM
angel.white angel.white is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Location: Kansas
Posts: 17 angel.white User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 40 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by sizablegrin
Documentation is all over the web (and not hard to find). A decent compiler usually has it also.

If you would read the documentation for fgets you would discover that a newline, if present, is always at the end. Consequently, if you remove all \r and \n from the end of the string, and the string is then of zero length, you have a blank line.

There is little penalty in modern systems for using single-character reads, such as you attempted, simply because most modern systems read and cache the entire file (or as much as they can). In a lesser system such actions would incur a horrible penalty because file operations are orders of magnitude slower than memory accesses.

Tossing in seeks (particularly one- or two-character movements) where they are absolutely unnecessary is also a questionable decision.

There are algorithms and there are languages and there are the systems. With enough abstraction one can forget about the systems, but one will never be an optimal user if one does so.
Thank you, can you suggest a place with good documentation? My book and most sites I find usually simply state how the function is declared, and have at most a simple paragraph explaining how to use it.

At one time I had found a wonderful site that had example code using each library function, but I did not bookmark it because I did not realize the rarity and utility of the site (I've since searched for it probably ten different times to no avail).

I would also absolutely love to see how the library functions are written. I've rewritten a few when I was unable to locate errors in my code and could not rule out the functions, it would be nice to compare them, as well as to learn. I'm particularly curious how the printf function works because I want to figure out how to dynamically send different numbers of variables to the function.

I use gcc on Ubuntu, is there a suggested method to check if it documents these functions (I'm rather new to linux as well).

Anyway, I appreciate the help in this thread, if I need to continue using C, I'll try to locate an in depth explanation of how files and file pointers work (if I can find the code for the functions that deal with this, I'll dissect that as well)

Reply With Quote
  #19  
Old May 7th, 2008, 07:45 AM
sizablegrin's Avatar
sizablegrin sizablegrin is online now
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,066 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 14 h 15 m 29 sec
Reputation Power: 1445
I don't know Ubuntu. I suspect, like most distros, it incorporates a manual called the "man pages". From the command-line type "man fopen", "man fgets", etc. You might even try "man man."

Reply With Quote
  #20  
Old May 7th, 2008, 12:39 PM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 2,405 clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 5 h 9 m 22 sec
Reputation Power: 320
Quote:
Originally Posted by angel.white
Thank you, can you suggest a place with good documentation?

I cannot believe that you suggested that C is not well documented! It has an ISO standard that defines it. Note that the standard library and the language itself are different things. So you need to be clear which you are referring when asking for documentation.

www.cplusplus.com has a comprehensive and detailed description of the C library. Don't be put off by the fact that it is C++ oriented. The only thing you need to be aware of is that in C++, C library headers have no extension and are prefixed with 'c', so <cstdio> should be replaced with <stdio.h> for example. In fact all the examples use the C form, which is also valid but deprecated in C++. I believe all the C library examples are purely C code and use no C++ specific syntax.

Another reasonably good library reference is www.cppreference.com. It is less user friendly perhaps that cplusplus.com, but fills some gaps perhaps. Again don't be put off by teh name, it covers the C library (which is a subset of the C++ library - if you did not know that then that may explain why you had trouble finding documentation).


A most comprehensive and up-to-date, but perhaps less user friendly library reference is www.dinkumware.com friendly.

In the end C is not a big language, and is not well served by a big reference. You would do well to get yourself a copy of "The C Programming Language" by Kernighan and Ritchie (often referred to as just K&R).

Documentation on both the language and the libraries can be found at http://publications.gbdirect.co.uk/c_book/. There are other tutorial resources you might consider listed at http://en.wikipedia.org/wiki/C_(pro...uage)#Tutorials .

Clifford

Reply With Quote
  #21  
Old May 7th, 2008, 12:48 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,442 Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level)Scorpions4ever User rank is Major General (70000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 h 49 m 40 sec
Reputation Power: 797
Quote:
Originally Posted by sizablegrin
I don't know Ubuntu. I suspect, like most distros, it incorporates a manual called the "man pages". From the command-line type "man fopen", "man fgets", etc. You might even try "man man."

Actually since Ubuntu is designed for users first, rather than programmers, it only installs part of the man pages by default. For programming, you'll need to install the following packages:

manpages-dev
manpages-posix
manpages-posix-dev

You can do this by using the Synaptics package manager or going to the command line and typing:
sudo apt-get install manpages-dev
and do the same thing for the other two packages.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > ANSI C: Checking for a blank line in an input file


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway