knking.com -- Programming Language Books and Training

 C C++ Java

Books by K. N. King

Home
Books by K. N. King
Short courses
Recommended books
Recommended links
FAQ

C Programming: A Modern Approach (Second Edition)

Chapter 25

Answers to Selected Exercises

6. [was #4; modified]

while ((orig_char = getchar()) != EOF) ??<
  new_char = orig_char ??' KEY;
  if (isprint(orig_char) && isprint(new_char))
    putchar(new_char);
  else
    putchar(orig_char);
??>

Answers to Selected Programming Projects

1. [was #2]

#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
  char *temp, *C_locale;

  temp = setlocale(LC_ALL, NULL);
    /* "C" is the current locale by default */
  if (temp == NULL) {
    printf("\"C\" locale information not available\n");
    exit(EXIT_FAILURE);
  }

  C_locale = malloc(strlen(temp) + 1);
  if (C_locale == NULL) {
    printf("Can't allocate space to store locale information\n");
    exit(EXIT_FAILURE);
  }

  strcpy(C_locale, temp);

  temp = setlocale(LC_ALL, "");
  if (temp == NULL) {
    printf("Native locale information not available\n");
    exit(EXIT_FAILURE);
  }

  if (strcmp(temp, C_locale) == 0)
    printf("Native locale is the same as the \"C\" locale\n");
  else
    printf("Native locale is not the same as the \"C\" locale\n");

  return 0;
}

Copyright © 2008, 1996 W. W. Norton & Company, Inc. All rights reserved.

Google
 
Web knking.com