home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!mips!darwin.sura.net!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc2.cs.uiuc.edu!pjl
- From: pjl@sparc2.cs.uiuc.edu (Paul Lucas)
- Subject: Re: Novice Questions
- Message-ID: <1992Aug26.001150.8237@sunb10.cs.uiuc.edu>
- Sender: news@sunb10.cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Aug24.235755.28424@athena.cs.uga.edu>
- Distribution: usa
- Date: Wed, 26 Aug 1992 00:11:50 GMT
- Lines: 45
-
- In <1992Aug24.235755.28424@athena.cs.uga.edu> aharris@athena.cs.uga.edu (Austin Harris) writes:
-
- >Hello, I have a couple of novice questions which I haven't been able to find
- >answers to in either my Turbo C++ or Waite group books. 1) Can you
- >return arrays from functions, if so what is the declaration and definition
- >syntax? I'm writing a simple program that does different types of string
- >reversing and thought that I should call a function with a string, and then
- >return that string reversed in different ways.
-
- *****> Array names (almost) always decay into a pointer to the first
- element, so _that's_ what you return--a pointer.
-
- >2) How can I count spaces in a string within a 'while not end of string' loop?
- >I know how to count other characters in a loop but not spaces.
-
- *****> Huh? If you can count the number of 'a's, you count the number
- of spaces that same way:
-
- for ( char const *c = s; *c; ++c )
- if ( *c == ' ' )
- ++count;
-
- For whitespace in general:
-
- #include <ctype.h>
-
- // ...
- if ( isspace( *c ) )
- // ...
-
-
- >What is the best way to look for the end of a string, do I just look for the
- >null zero?
-
- *****> Yes.
-
- >What if there are other zeros in my string?
-
- *****> There can't be; if you need that functionality, you can't use C
- "strings"; you'll have to maintain a character-count (like Pascal
- strings).
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-