Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

DOS tool to convert letters in text file to upper/lowercase. (Miscellaneous)

posted by jhall Homepage, 28.10.2022, 16:24

Or, you could write a small program to do this for you. Compile this:

#include <stdio.h>

#define is_upper(A) ((A >= 'A') && (A <= 'Z'))
#define is_lower(A) ((A >= 'a') && (A <= 'z'))

#define to_lower(A) (A - 'A' + 'a')
#define to_upper(A) (A - 'a' + 'A')

int
main()
{
  int ch;

  while ((ch = getchar()) != EOF) {
    if (is_upper(ch)) {
      putchar( to_lower(ch) );
    }
    else {
      putchar(ch);
    }
  }

  return 0;
}


This is a very simple program (it doesn't read files, it relies on file redirection) to convert text from uppercase to lowercase. It leaves all other characters as they are (such as punctuation, numbers, etc.)

Save it as tolower.c and compile it with

> WCL tolower.c

(You'll need to install the Watcom C Compiler package and run the OWSETENV.BAT file to set your environment.)

To turn this program into a "convert to uppercase" program, copy the file to toupper.c and change the two lines inside the while loop to this:

    if (is_lower(ch)) {
      putchar( to_upper(ch) );


Then compile the new program with:

> WCL toupper.c

 

Complete thread:

Back to the forum
Board view  Mix view
22155 Postings in 2045 Threads, 396 registered users, 19 users online (0 registered, 19 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum