home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12884 < prev    next >
Encoding:
Text File  |  1992-08-25  |  2.0 KB  |  58 lines

  1. Newsgroups: comp.lang.c++
  2. 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
  3. From: pjl@sparc2.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Novice Questions
  5. Message-ID: <1992Aug26.001150.8237@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Aug24.235755.28424@athena.cs.uga.edu>
  9. Distribution: usa
  10. Date: Wed, 26 Aug 1992 00:11:50 GMT
  11. Lines: 45
  12.  
  13. In <1992Aug24.235755.28424@athena.cs.uga.edu> aharris@athena.cs.uga.edu (Austin Harris) writes:
  14.  
  15. >Hello, I have a couple of novice questions which I haven't been able to find
  16. >answers to in either my Turbo C++ or Waite group books.  1) Can you
  17. >return arrays from functions, if so what is the declaration and definition
  18. >syntax?  I'm writing a simple program that does different types of string
  19. >reversing and thought that I should call a function with a string, and then
  20. >return that string reversed in different ways.
  21.  
  22. *****>    Array names (almost) always decay into a pointer to the first
  23.     element, so _that's_ what you return--a pointer.
  24.  
  25. >2) How can I count spaces in a string within a 'while not end of string' loop?
  26. >I know how to count other characters in a loop but not spaces.
  27.  
  28. *****>    Huh?  If you can count the number of 'a's, you count the number
  29.     of spaces that same way:
  30.  
  31.         for ( char const *c = s; *c; ++c )
  32.             if ( *c == ' ' )
  33.                 ++count;
  34.  
  35.     For whitespace in general:
  36.  
  37.     #include <ctype.h>
  38.  
  39.         // ...
  40.             if ( isspace( *c ) )
  41.                 // ...
  42.  
  43.  
  44. >What is the best way to look for the end of a string, do I just look for the
  45. >null zero?
  46.  
  47. *****>    Yes.
  48.  
  49. >What if there are other zeros in my string?
  50.  
  51. *****>    There can't be; if you need that functionality, you can't use C
  52.     "strings"; you'll have to maintain a character-count (like Pascal
  53.     strings).
  54. -- 
  55.     - Paul J. Lucas                University of Illinois    
  56.       AT&T Bell Laboratories        at Urbana-Champaign
  57.       Naperville, IL            pjl@cs.uiuc.edu
  58.