• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

Why printf() does not print?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again and Happy New Year 2019!

I am learning C from the book "The C Programming Language" second edition by Brian Kernighan and Dennis Ritchie. There are a couple examples (character and line counting) that do not work for me when I code them. For example, line counting is:



Does not print even though it compiles and runs just fine. I can enter lines of text but it will not print how many lines have been entered. What is wrong?
 
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working.please check
 
Shubham Rai
Ranch Hand
Posts: 45
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is working.please check Ideone
 
Marshal
Posts: 4225
557
Android Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Adrian Meneses wrote:Does not print even though it compiles and runs just fine. I can enter lines of text but it will not print how many lines have been entered. What is wrong?


The code is going to stay ion the while loop until there is no more input - how are you terminating your input?  From the Linux command line, you would normally use Control-D:
You could also test by redirecting standard input from a file:
 
Adrian Meneses
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Adrian Meneses wrote:Does not print even though it compiles and runs just fine. I can enter lines of text but it will not print how many lines have been entered. What is wrong?


The code is going to stay ion the while loop until there is no more input - how are you terminating your input?  From the Linux command line, you would normally use Control-D:
You could also test by redirecting standard input from a file:


Thank you! I am not familiar with the EOF in the library and because of that I was terminating the program with Control-C.
 
Rancher
Posts: 494
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Adrian

What environment are you running this in eg. Linux, Windows? How exactly are you running/testing it?
 
John Matthews
Rancher
Posts: 494
15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Matthews wrote:Hi Adrian

What environment are you running this in eg. Linux, Windows? How exactly are you running/testing it?


Apologies for the (sort of) duplicate post - when I started my reply no one else had posted, then I got distracted
 
Saloon Keeper
Posts: 26894
192
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Linux (and Unix/MacOS) operate using signals. You can send a signal to a process with the "kill" command, which despite its name, doesn't actually kill processes, just targets the indicated process(es) for the designated signal. For example, the infamous "kill -9", which terminates a process immediately.

The CTRL-C code when issued in a command shell gets translated into a "kill -2" (SIGINT) that is sent to the currently-running application in that particular shell. The CTRL-D becomes a SIGQUIT, which the the stdin processor interprets as meaning "end of data". SIGINT by default kills a process, but since you can re-assign signal handling can also be used to do things like indicate a change in the environment so that the application would re-read its configuration files (as a common example).

SIGQUIT is preferable to SIGINT for terminating an application, because it allows the program logic to see end-of-file and do whatever post-data operations need to be done, whereas SIGINT kills the whole app without cleaning up (unless the app has configured a SIGINT handler routine).

If no application is running in a bash shell, SIGINT simply causes the shell to type "^C", but SIGQUIT causes the shell to terminate (logout).
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic