473,435 Members | 1,622 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,435 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 1891
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.