473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

A little help with this code!

14
I have to modify the code below so that it counts the number of times the user presses Ctrl-C. The new program will print th emessage OUCH!, then OUCH!!, where the number of exclamation points equals the number of times the handler has been called.

In addition, to printing an increasing number of exclamation points, the program should accept an integer as a command line argument. After the user presses Ctrl-C that many times, the program should exit.

In addition the line sleep(1); has the following error message: implicit declaration of function 'int sleep(...)'

Please advise.

Thanks.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <signal.h>
  3.  
  4. main()
  5. {
  6.     void f(int);
  7.     int  i;
  8.     signal( SIGINT, f );
  9.     for(i=0; i<5; i++ ){
  10.         printf("hello\n");
  11.         sleep(1);
  12.     }
  13. }
  14. void f(int signum)
  15. {
  16.     printf("OUCH!\n");
  17. }
  18.  
Jul 1 '09 #1
4 1890
stayit
14
This might have something to do with Unix if it affects the code at all.
Jul 1 '09 #2
donbock
2,426 Expert 2GB
@stayit
The error message occurs because there is no function prototype to explicitly declare the function. Lacking an explicit declaration, the compiler implicitly assumes a default declaration: that the function returns an int and can take an arbitrary parameter list (which may not be what the function really does). The error message alerts you that the implicit declaration took place. You need to include whichever header declares that function.

Is that your only problem?
Jul 1 '09 #3
stayit
14
I also have the problem of trying to get the number of exclamation points in the code as noted above.
Jul 1 '09 #4
donbock
2,426 Expert 2GB
To print a string of exclamation points whose length is equal to the number of Ctrl-C inputs received involves three steps:
  1. Detect Ctrl-C event
  2. Keep a count of those events
  3. Report the event count via string of exclamation points.
Which of those steps are you having trouble with?
Jul 2 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Ron Stephens | last post by:
I posted to my web site a fun little program called merlin.py today. Please keep in mind that I am a hobbyist and this is just a little hack, if you look at the code you will see that it is still...
5
by: Tongu? Yumruk | last post by:
I have a little proposal about type checking in python. I'll be glad if you read and comment on it. Sorry for my bad english (I'm not a native English speaker) A Little Stricter Typing in Python...
38
by: Martin Marcher | last post by:
Hi, I've read several questions and often the answer was 'C knows nothing about .' So if C knows that little as some people say, what are the benefits, I mean do other languages know more...
8
by: Perception | last post by:
Hello all, If I have a C-like data structure such that struct Data { int a; //16-bit value char; //3 ASCII characters int b; //32-bit value int c; //24-bit value }
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
2
by: petermichaux | last post by:
Hi, It seems like determining element position in a web page is a difficult task. In the position reporting source code I've looked at there are special fixes for at least some versions of...
13
by: junky_fellow | last post by:
Hi guys, I need to convert a big endian integer to little endian integer. (the integer is 4 bytes in size on my implementation). I came up with the following code. I need your comments on...
13
by: mdh | last post by:
K&R devote 4 exercises to Detab/Entab issues. An extremely cursory search reveals entire religions following space vs tab controversy....so, I guess the exercises are not in a complete vacuum. My...
0
by: Just_a_fan | last post by:
I am so happy about this I had to tell someone and since no one at the house even knows how to spell VB, I just had to make a short post. I finally got my little program to correctly do a second...
3
by: Ethan Furman | last post by:
len wrote: I've never had the (mis?)fortune to work with COBOL -- what are the files like? Fixed format, or something like a dBase III style? I
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.