Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 28th, 2004, 3:42 AM   #11
Option_Explicit
Programmer
 
Join Date: Dec 2004
Posts: 31
Rep Power: 0 Option_Explicit is on a distinguished road
Come on, I know you guys know what it means.
-Mike
Option_Explicit is offline   Reply With Quote
Old Dec 28th, 2004, 4:34 AM   #12
Ravilj
Programmer
 
Ravilj's Avatar
 
Join Date: Sep 2004
Location: JHB , South Africa
Posts: 79
Rep Power: 5 Ravilj is on a distinguished road
Option Explicit: All they saying is if you want read in a single key from the keyboard ie: user input than use getChar( ). Here is an example:
char c;
printf( "Are you sure you want to exit: [Y/N]");
c = getChar( );

if ( c == 'Y' ) 
{
// exit program
 return 0;
}

if ( c== 'N' ) 
{
// do something else
}

putChar( c ); Is just used to display the character stored in c on the screen.
__________________
Ravilj's OpenGL Terrain aka WinTerrain Last Updated: 17/01/2005!
Ravilj is offline   Reply With Quote
Old Dec 28th, 2004, 2:43 PM   #13
Option_Explicit
Programmer
 
Join Date: Dec 2004
Posts: 31
Rep Power: 0 Option_Explicit is on a distinguished road
I started to re-read it and it made a bit more sense, but your explanation clarified almost all of it. Thanks a lot Ravilj, this section makes a lot more sense now.
-Mike
Option_Explicit is offline   Reply With Quote
Old Dec 29th, 2004, 4:24 PM   #14
Option_Explicit
Programmer
 
Join Date: Dec 2004
Posts: 31
Rep Power: 0 Option_Explicit is on a distinguished road
I have another question! I got more into the getchar and putchar commands and wrote the example code out. Supposedly it counts input lines but I'm not sure what exactly the program does. If anyone could clarify, it would be helpful.
#include <stdio.h>

main()
{
     long nc;
     
     nc = 0;
     while (getchar() != EOF)
        ++nc;
     printf("%1d\n", nc);
}
-Mike
Option_Explicit is offline   Reply With Quote
Old Dec 29th, 2004, 6:09 PM   #15
Tama
Programmer
 
Join Date: Dec 2004
Posts: 35
Rep Power: 0 Tama is on a distinguished road
>Supposedly it counts input lines
A line is any sequence of characters ending with '\n'. The code as posted counts the number of characters, not the number of lines.

>while (getchar() != EOF)
getchar reads a character. If it's anything but the macro EOF (which designates an error or the end of input) then nc is incremented.

If you want to count the number of lines then this would be more appropriate:
#include <stdio.h>

int main(void)
{
 long int nl = 0; /* Counter for the lines */
 int ch;     /* Used to save the input character for testing */

 /* Read characters until EOF and save them in ch */
 while ((ch = getchar()) != EOF) {
  /* Is ch an end of line marker? */
  if (ch == '\n')
   ++nl;
 }
 /* Match the format modifier with the variable type. */
 /* %ld is used for long int, not %d */
 printf("# of lines: %ld\n", nl);

 /* Always return a value! */
 return 0;
}
Tama is offline   Reply With Quote
Old Dec 31st, 2004, 3:59 AM   #16
Option_Explicit
Programmer
 
Join Date: Dec 2004
Posts: 31
Rep Power: 0 Option_Explicit is on a distinguished road
Thank you Tama; I was actually looking at the wrong page when I entered the previous code, so it makes much more sense now. Thank you for clarifying this for me. Oh and the book I am using never mentioned returning zero, but I understand what it does, so I shall make sure I include that in my writing.
-Mike
Option_Explicit is offline   Reply With Quote
Old Dec 31st, 2004, 9:41 AM   #17
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
i personally use Dev-C++ as an editor and i use borland (free command-line tools) as a compiler. ooble has posted a reply from me earlier on this forum about a simple way to configurate borland so that it is very simple to use.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:31 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC