Sponsored Content
Top Forums Programming C Beginner Looking For Suggestions Post 302302625 by jim mcnamara on Tuesday 31st of March 2009 01:10:06 PM
Old 03-31-2009
Here is one way:
Code:
#include <stdio.h>
#define SPC 32

int main()
{
  int c=0;
  int space=0;
  space = 0;

  while ((c=getchar()) != EOF) 
  {
      space=(c==SPC) ? space+1 : 0;
      if(space < 2 ) 
         putchar(c);
  }
  
  return 0;
}

space=(c==SPC) ? space+1 : 0;

Is another way of writing if c equals space add one to space else move 0 to space.

#define SPC 32
Defining constants is good practice.

Bad: this code never checks return values of functions. It would fail lint.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Suggestions on where to begin?

I have been a student at Hendrix Institute for about a year now. My term is comming to an end by the end of december. I have learned varios computer programs for web development that include Flash 5 and Dreamweaver. Actionscripting, Javascript and Database development with Access was all... (4 Replies)
Discussion started by: andrew25008
4 Replies

2. UNIX for Dummies Questions & Answers

Suggestions wanted ...

All, Have an AMD-K6/2 PC, 20G.Hd along with RH7.2. Wanting to know what I should do in terms of setup (workstation/server) and then what I can do with it? I'd like to learn a DBMS and SQL - can I do this using RedHat? Any suggestions with how I can use/ what I can do with this appreciated. (3 Replies)
Discussion started by: Cameron
3 Replies

3. UNIX for Dummies Questions & Answers

Backup suggestions

The current backup procedure we using a tar command in linux. The files are stored in one partition in different folders. The docs stores in day wise folders like ex: /usr/data/xyz/20050129, /usr/data/xyz/20050130 .............etc We using tar & gzip command to take backup everyday. The backup... (3 Replies)
Discussion started by: bache_gowda
3 Replies

4. UNIX for Advanced & Expert Users

Looking for Suggestions...

We run WebSphere and by default it wants to install everything under /usr. While I can understand the default (everyone has a /usr) I would like to move this over to a dedicated volume group called apps and then setup my lv's and fs's here. Our WebSphere Admin doesn't like this because apparently... (1 Reply)
Discussion started by: scottsl
1 Replies

5. Solaris

Suggestions Req

Hi all, I have worked on HP UNIX and now i have moved to SunSolaris which i never used to work. I am more on programming side like shell and perl scripting. So i want to know from you experts that i need to take care or changes which i code in sun solaris in compared to HP unix. Suggestions... (1 Reply)
Discussion started by: ravi.sadani19
1 Replies

6. Shell Programming and Scripting

Suggestions on input

Hi, I have written a script which calls a process which ends up in a reboot of the system. At the end of the reboot it prompts for login & i need to provide the login details. am not able to figure out hw to do this. Doubt: will echoing login details after calling the process work? for ex:... (1 Reply)
Discussion started by: meera
1 Replies

7. UNIX for Advanced & Expert Users

Need suggestions.......

Hello there....i am a final year comp science student.......i am thinking of doing my project on unix platform......which one do u suggest?thanx in advance... (3 Replies)
Discussion started by: theprasad1990
3 Replies

8. Solaris

Suggestions for new T5140

I've been busy and fell behind on Sun/Oracle. Forgive me if too basic. I welcome brief, cryptic, or advanced replies. I also welcome noobie information since I may have no clue what's up at the moment. Problem statement: I inherited a computer to set up. I would rather not figure out 8 months... (1 Reply)
Discussion started by: Nevyn
1 Replies

9. UNIX for Dummies Questions & Answers

Suggestions for the interview

Hi guys, i'm undergoing a traning in solaris administration and i request if any one have an idea on the interview questions on solaris. thank you. (3 Replies)
Discussion started by: 038karthik
3 Replies

10. Shell Programming and Scripting

Suggestions on this script please

i=1 out="" j=`expr 2 * $1` while do out="$out"#"" echo $out ((i=i+1)) done while do print ${out%?} ((i=i+1)) done This script is throwing an error: gurnish:/home/fnb/gurnish/saurabh/scripts> while1 3 expr: 0402-050 Syntax error. # (6 Replies)
Discussion started by: targetshell
6 Replies
sigspace(2)							System Calls Manual						       sigspace(2)

NAME
sigspace - assure sufficient signal stack space SYNOPSIS
DESCRIPTION
requests additional stack space that is guaranteed to be available for processing signals received by the calling process. If the value of stacksize is positive, it specifies the size of a space, in bytes, which the system guarantees to be available when pro- cessing a signal. If the value of stacksize is zero, any guarantee of space is removed. If the value is negative, the guarantee is left unchanged; this can be used to interrogate the current guaranteed value. When a signal's action indicates that its handler should use the guaranteed space (specified with a or call (see bsdproc(3C)), the system checks to see if the process is currently using that space. If the process is not currently using that space, the system arranges for that space to be available for the duration of the signal handler's execution. If that space has already been made available (due to a previous signal), no change is made. Normal stack discipline is resumed when the signal handler first using the guaranteed space is exited. The guaranteed space is inherited by child processes resulting from a successful system call, but the guarantee of space is removed after any system call (see fork(2) and exec(2)). The guaranteed space cannot be increased in size automatically, as is done for the normal stack. If the stack overflows the guaranteed space, the resulting behavior of the process is undefined. Guaranteeing space for a stack can interfere with other memory allocation routines in an implementation-dependent manner. During normal execution of the program, the system checks for possible overflow of the stack. Guaranteeing space might cause the space available for normal execution to be reduced. Leaving the context of a service routine abnormally, such as by (see setjmp(3C)), removes the guarantee that the ordinary execution of the program will not extend into the guaranteed space. It might also cause the program to lose forever its ability to automatically increase the stack size, causing the program to be limited to the guaranteed space. RETURN VALUE
Upon successful completion, returns the size of the former guaranteed space. Otherwise, it returns -1 and sets to indicate the error. ERRORS
fails and the guaranteed amount of space remains unchanged if the following occurs: [ENOMEM] The requested space cannot be guaranteed, either because of hardware limitations or because some software- imposed limit would be exceeded. WARNINGS
The guaranteed space is allocated using malloc(3C). This use might interfere with other heap management mechanisms. Methods for calculating the required size are not well developed. Do not use in conjunction with the facilities described under sigset(3C). Do not use in conjunction with sigstack(2). In HP-UX release 11.11, use of in threads created with process contention scope could result in undefined behavior. This function will continue to be reliable in threads created with system contention scope. APPLICATION USAGE
Threads Considerations Each thread may define an alternate signal handling stack. LWP (Lightweight Processes) Considerations Each LWP may define an alternate signal handling stack. AUTHOR
was developed by HP. SEE ALSO
sigaction(2), sigstack(2), malloc(3C), setjmp(3C). sigspace(2)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy