LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-06-2007, 06:43 AM   #1
Indiestory
Member
 
Registered: Aug 2006
Location: Aberdeen, Scotland
Distribution: OpenBSD
Posts: 164
Blog Entries: 1

Rep: Reputation: 30
No output from printf


Im trying to learn C using The C programming language second edition, based on the reviews section here. Im not learning to program, i have experience with other languages, mostly VB ,but some C++ and a little tcl/tk.

Im following the examples in this book and im some way into the, but none of the examples involving word and line counting are returning any out put.

Code:
#include <stdio.h>

main() 
{
  long nc;

  nc = 0;
  
  while (getchar() != EOF)
	++nc;
  printf("%ld\n", nc);

}
this should return the number of characters on the line you typed in. I takes the input but then returns nothing. Im thinking this may have something to do with the EOF, but that doesnt seem like a problem between unix's. This example was compiled on OSX because thats what i was sitting at when i picked up the book. It have between 4. something, cheers for any help
 
Old 01-06-2007, 07:33 AM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi,
your program work fine, maybe you are using it wrongly
Keep in mind that you need to press CTRL+D to send the EOF character to your program.
So if you type:

Code:
Hello
CTRL+D
you will get a nice 6 afterwards (Hello is 5 characters + the newline character).


Cheers!
 
Old 01-06-2007, 07:52 AM   #3
Indiestory
Member
 
Registered: Aug 2006
Location: Aberdeen, Scotland
Distribution: OpenBSD
Posts: 164

Original Poster
Blog Entries: 1

Rep: Reputation: 30
thanks that worked, i have to enter the newline twice but its printing the info, thanks for the help may be back as i get deeper into this language
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printf: postion cursor to output columns schneidz Programming 5 09-20-2005 08:59 AM
Output problems with printf pateldenish Programming 1 02-24-2005 09:02 AM
How does printf work? Ephracis Programming 1 12-25-2004 03:06 AM
printf output with commas eastsuse Linux - General 1 03-09-2004 07:26 PM
printf new_user10 Programming 3 09-09-2003 11:12 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration