[Courses] re: [C] lesson 7

KWMelvin kwmelvin at intrex.net
Tue Nov 5 12:49:55 EST 2002


Hello!

Can you assign one array to another? In your code, you do this:
    returnchar = "vowel";
Does that work?  How about this (see Lesson Four):
    strcpy(returnchar, "vowel");

This seems like a great idea.  Is this how C `libraries' are made?
What would you call the header file at this point? vowel.h?  How
would you use it?  Is this a valid way to use it?:

#include <stdio.h>
#include "vowel.h"
int main(void)
{
  printf("%s\n", consonent_or_vowel('a'));
  return 0;
}

In the LOGO programming language there are things called
`predicates'.  A predicate is an operation whose output is
always either the word true or the word false.  So in LOGO,
there would be a predicate called `vowelp':

  to vowelp :letter
  output memberp :letter [ a e i o u]
  end

This would be used like this:

  ? print vowelp "e
  true
  ? print vowelp "g
  false

It seems that the C programming language doesn't have BOOLEAN,
in it like Pascal does. In Pascal, the Boolean data type returns
true or false. So, using the Boolean type, Pascal programmers
can create functions (procedures) like: isvowel(ch), or isdigit(ch).

The C Standard library does have the following predefined functions
in the <ctype.h> header:

Function | Description
---------+------------------------------------
isalnum  | Test for Alphanumeric
isalpha  | Test for Alphabetic
iscntrl  | Test for Control Character
isdigit  | Test for Digit
isgraph  | Test for Graphical Character
islower  | Test for Lower-Case Letter
isprint  | Test for Printing Character
ispunct  | Test for Punctuation Character
isspace  | Test for White-Space Character
isupper  | Test for Upper-Case Letter
isxdigit | Test for Hex Digit
---------+-------------------------------------

Happy Programming!
--
K

On Sun, Nov 03, 2002 at 04:29:39PM -0500, Morgon Kanter wrote:
> Hello,
> 
> After doing the lesson 7 excercises, I thought it would be a good idea to 
> make a header file of some of the common stuff we'd been doing. So here is 
> one of the excercises.
> 
> char consonent_or_vowel(char letter) {
>  char returnchar[10];
>
> <switch statement snipped for brevity>
>  
>  returnchar = "consonent";
>  break;
> default:
>  returnchar = "vowel";
>  break;
>  }
>  return returnchar;
> }
> 
> If I made an error, please let me know.
> 



More information about the Courses mailing list