home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1990 MetaWare Incorporated; All Rights Reserved */
-
- /**** name=abort ****/
- #define main TEST_abort
-
- /*
- The program fragment below aborts the program with a message if all is
- not okay.
- */
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- int i = 0;
-
- if (i != 1) {
- fprintf(stderr, "Terminate right now!");
- abort();
- }
- printf("\n This line will never print.\n");
- }
- /* End abort */
- #undef main
- /**** name=abs ****/
- #define main TEST_abs
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- int absolut, posneg = -32;
-
- absolut = abs(posneg);
- printf("The absolute value of %d is: %d\n",
- posneg, absolut);
- }
- /* End abs */
- #undef main
- /**** name=_access ****/
- #define main TEST__access
-
- /*
- This program reports the access rights of file test.dat.
- */
-
- #include <io.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char *name = "test.dat";
- int exists = 0;
- int readonly = 0;
-
- exists = _access(name, 0) == 0;
- readonly = _access(name, 2) == -1;
-
- if (exists && readonly)
- puts("test.dat has read-only access.");
- else if (exists && !readonly)
- puts("test.dat has read/write access.");
- else
- puts("File test.dat not found.");
- }
-
- /* End _access */
- #undef main
- /**** name=_alloca ****/
- #define main TEST__alloca
-
- /*
- alloca must never be used as an argument to a function. It is inherently
- unreliable in concept. The function is provided only for compatibility.
- */
-
- #include <malloc.h>
- #include <stdio.h>
-
- pragma off(Postpone_arg_pops); /* Required. */
- pragma off(Optimize_FP); /* Required. */
- void main() {
- int m, j[15], *k;
-
- k = alloca(sizeof(j) * sizeof(j[0]));
- printf("Allocated space on stack.\n");
- for (m = 0; m <= 15; m++) {
- if ((m==0) || (m==1))
- k[m]=1;
- else
- k[m] = k[m-1] + k[m-2]; /* Fibonacci sequence */
- }
- printf("Space is allocated and "
- "contained the Fibonacci sequence.\n");
- for (m = 0; m <= 13; m++) {
- if (k[m] == 0)
- printf("Error, element k[%d] is zero.\n", m);
- else
- printf("%d, ",k[m]);
- }
- printf("\nDone.\n");
- }
- /* End _alloca */
- #undef main
- /**** name=asctime ****/
- #define main TEST_asctime
-
- /*
- This example illustrates the use of asctime() with time() and
- localtime().
- */
- #include <time.h>
- #include <stdio.h>
-
- void main() {
- time_t t;
-
- time(&t);
- printf("Local time: %s", asctime(localtime(&t)));
- }
- /* End asctime */
- #undef main
- /**** name=asin ****/
- #define main TEST_asin
-
- /*
- This function shows the behavior of asin and sin. Note that the
- argument to asin is a constant and its return is a radian value.
- */
-
- #include <errno.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- double x, value = 0;
-
- for (;;) { /* Go until error is created. */
- x = asin(value);
- printf("\nasin(%lf)", value);
- if (errno == EDOM) {
- printf("\nDomain error. value = %lf", value);
- return;
- }
- else
- printf("\nasin returns angle:"
- " %lf radian\t %lf degrees",
- x, 180.0/_PI * x );
- value = value + 0.6;
- }
- }
- /* End asin */
- #undef main
- /**** name=assert ****/
- #define main TEST_assert
-
- #include <assert.h>
- #include <stdio.h>
- #include <stdlib.h> /* Get abort() declaration. */
-
- void main() {
- int i = 0;
-
- assert(!i);
- printf("\nProgram is running, but"
- " will fail soon.\n");
- assert(i == 1);
- printf("\nProgram still running.\n");
- }
- /* End assert */
- #undef main
- /**** name=atan ****/
- #define main TEST_atan
-
- #include <errno.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- double x = 0.0;
-
- for(;;) {
- printf("\natan(%f) = %f radians\t%f degrees",
- x, atan(x), 180.0/_PI * atan(x));
- x = exp(x);
- if (errno) { /* Check for error in exp(). */
- printf("\n An error has occurred. Bye ...");
- return;
- }
- }
- }
- /* End atan */
- #undef main
- /**** name=atan2 ****/
- #define main TEST_atan2
-
- #include <stdio.h>
- #include <math.h>
- void main() {
- double x = 1.0, y = 1.55741;
- printf("%e %e\n", atan2(y,x), atan2(-y,x));
- printf("%e %e\n", atan2(y,-x), atan2(-y,-x));
- }
- /* End atan2 */
- #undef main
- /**** name=atexit ****/
- #define main TEST_atexit
-
- #include <stdio.h>
- #include <stdlib.h>
- void func(void);
-
- void main() {
-
- atexit(func);
- printf("Watch for the atexit message"
- " when the program ends.\n");
- }
-
- void func(void) {
- printf("\nThe atexit test is now finished.\n");
- }
- /* End atexit */
- #undef main
- /**** name=atof ****/
- #define main TEST_atof
-
- /*
- The program below displays a number as a string and as a float.
- */
- #include <stdlib.h>
- #include <stdio.h>
- void main() {
- char pi[] = "3.141593";
- printf("String pi is %s. ", pi);
- printf("Float pi is %.6f.\n", atof(pi));
- }
- /* End atof */
- #undef main
- /**** name=atoi ****/
- #define main TEST_atoi
-
- /*
- The program below displays a number as a string and as an int.
- */
- #include <stdlib.h>
- #include <stdio.h>
- void main() {
- char num[] = "412";
- printf("String number is %s.\n", num);
- printf("Int number is %d.\n", atoi(num));
- }
- /* End atoi */
- #undef main
- /**** name=atol ****/
- #define main TEST_atol
-
- /*
- The program below displays a number as a string and as an int.
- */
- #include <stdlib.h>
- #include <stdio.h>
- void main() {
- char num[] = "1267543";
- printf("String number is %s.\n", num);
- printf("Long int number is %d.\n", atol(num));
- }
- /* End atol */
- #undef main
- /**** name=_bdos ****/
- #define main TEST__bdos
-
- #include <dos.h>
-
- void main() {
- char msg[] = "Display this on the screen.\r\n";
- int k = 0;
-
- while (msg[k]!=0)
- _bdos(2,msg[k++],0);
- }
- /* End _bdos */
- #undef main
- /**** name=_bios_disk ****/
- #define main TEST__bios_disk
-
- /*
- This program tests status of Drive C.
- Assumes High C users will always have a hard disk drive.
- */
-
- #include <stdio.h>
- #include <bios.h>
-
- void main() {
- unsigned status = 0;
- struct diskinfo_t info;
-
- info.drive = 0x80; /* Drive C: */
- info.head = 0; /* Use the boot sector. */
- info.track = 0;
- info.sector = 1;
- info.nsectors = 1;
- info.buffer = 0;
-
- status = _bios_disk(_DISK_STATUS, &info);
- printf("Status of disk drive C: is %x",status);
- }
- /* End _bios_disk */
- #undef main
- /**** name=_bios_equiplist ****/
- #define main TEST__bios_equiplist
-
- /*
- Program detects various hardware attachments.
- */
- #include <stdio.h>
- #include <bios.h>
-
- void main() {
- unsigned equip; /* Holder for return value. */
- unsigned bits; /* Holder for isolated bits. */
-
- equip = _bios_equiplist(); /* Call the function. */
- printf("equip => %x\n\n", equip);
- bits = equip & 0x1; /* Mask bit 0 first. */
- if (bits == 1) {
- bits = equip & 0xC0; /* Bits 6 and 7 for */
- /* number of drives. */
- bits=bits >> 6; /* Shift right to get */
- /* number. */
-
- printf("%i floppy disk(s) installed"
- "\n", bits + 1);
- }
- else printf("No floppy disks installed\n");
- bits = equip & 0x2; /* Mask bit 1. */
- if(bits == 2)
- printf("Math coprocessor installed.\n");
- else printf("No math coprocessor installed.\n");
- bits = equip & 0x100; /* Mask bit 8. */
- if(bits == 0)
- printf("DMA chip is installed.\n");
- else printf("No DMA chip is installed.\n");
- bits = equip & 0x1000; /* Mask bit 12. */
- if(bits == 2048)
- printf("Game adapter is installed.\n");
- else printf("Game adapter is not installed.\n");
- bits = equip & 0x2000; /* Mask bit 13. */
- if(bits == 4096)
- printf("Serial printer attached.\n");
- else printf("Serial printer is not attached.\n");
- }
-
- /* End _bios_equiplist */
- #undef main
- /**** name=_bios_keybrd ****/
- #define main TEST__bios_keybrd
-
- /*
- This program tests keyboard read and status functions.
-
- */
- #include <stdio.h>
- #include <bios.h>
- void main() {
- unsigned key = 0; /* Return value. */
- char bits[10]; /* Status bit pattern. */
- int pow2[8] = {128,64,32,16,8,4,2,1};
- int i;
-
- while ((char) key != 27) {
- printf("\nPress any key to test, or "
- "ESC to quit\n");
-
- /* Loop until something happens. */
- while ((_bios_keybrd(_KEYBRD_READY))==0);
- /* Check for ESC. */
- key = _bios_keybrd(_KEYBRD_READ);
- if ((char)key != 27) {
- printf("You entered %c \n",key);
- if ((key =
- _bios_keybrd(_KEYBRD_SHIFTSTATUS)) != 0) {
- for ( i = 0; i <= 7; i++) {
- if (((char)key & pow2[i]) != 0)
- bits[i] = '1';
-
- else
- bits[i] = '0';
- }
- bits[8] = 0;
- printf("With a status bit pattern of %s"
- "\n",bits);
- }
- }
- }
- }
- /* End _bios_keybrd */
- #undef main
- /**** name=_bios_memsize ****/
- #define main TEST__bios_memsize
-
- /*
- This program prints the amount of system memory.
- */
-
- #include <stdio.h>
- #include <bios.h>
-
- void main() {
- unsigned memsize;
-
- memsize = _bios_memsize();
- printf("The amount of system memory "
- "is %uKB \n", memsize);
- }
- /* End _bios_memsize */
- #undef main
- /**** name=_bios_printer ****/
- #define main TEST__bios_printer
-
- /*
- This program tests the printer output and status functions.
- */
-
- #include <stdio.h>
- #include <bios.h>
- #define LPT1 0
- void main() {
- unsigned status; /* Receives return value. */
- unsigned data; /* Output data. */
- char bits[10]; /* Status bit pattern. */
-
- static int pow2[8] = {128,64,32,16,8,4,2,1};
- int i;
-
- data = 0xff;
- status = _bios_printer(_PRINTER_STATUS, LPT1, data);
-
- for (i = 0; i <= 7; i++) {
- if (((char)status & pow2[i]) != 0)
- bits[i] = '1';
- else
- bits[i] = '0';
- }
- bits[8] = 0;
- printf("Status bit pattern of LPT1:"
- " %s \n",bits);
- }
- /* End _bios_printer */
- #undef main
- #undef LPT1
- /**** name=_bios_serialcom ****/
- #define main TEST__bios_serialcom
-
- /*
- This program tests serial-port functions.
- */
-
- #include <stdio.h>
- #include <bios.h>
- #define _COM1 0
-
- void main() {
- int i;
- unsigned data; /* Output byte. */
-
- unsigned status; /* Return value. */
- char bits[18]; /* Status bit pattern. */
- static int pow2[16] =
- {1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
- 1024, 2048, 4096, 8192, 16384,32768};
-
- data = _COM_CHR8 | _COM_STOP1 | _COM_NOPARITY |
- _COM_2400;
- status = _bios_serialcom(_COM_STATUS,_COM1,data);
-
- for (i = 0; i <= 15; i++) {
- if ((status & pow2[15 - i]) != 0)
- bits[i] = '1';
- else
- bits[i] = '0';
- }
- bits[16] = 0;
- printf("Status bit pattern of COM1:%s \n", bits);
- }
- /* End _bios_serialcom */
- #undef main
- #undef _COM1
- /**** name=_bios_timeofday ****/
- #define main TEST__bios_timeofday
-
- /*
- This program counts the number of clock ticks for 1,000 iterations of a
- function.
- */
- #include <stdio.h>
- #include <bios.h>
- #include <math.h>
- void main() {
- long i, start, stop;
- double x = 0.75, t1 = 0.50025;
-
- puts("Testing _bios_timeofday...\n");
- _bios_timeofday (_TIME_GETCLOCK, &start);
- printf("Start tick count: %lu\n", start);
- printf("Doing 1000 iterations "
- "of: sqrt(exp(log(x)/t1))...\n");
- for (i=0; i<=1000; i++)
- x = sqrt(exp(log(x)/t1));
- _bios_timeofday (_TIME_GETCLOCK, &stop);
- printf("Stop tick count: %lu\n", stop);
- printf("-----------------\n");
- printf("Total ticks : %lu\n\n", stop - start);
- stop = 0;
- _bios_timeofday (_TIME_GETCLOCK, &start);
- printf("Start tick count: %lu\n", start);
- printf("Doing 1000 iterations "
- "of: sqrt(exp(log(x)/t1))...\n");
- for (i=0; i<=1000; i++)
- x = sqrt(exp(log(x)/t1));
- _bios_timeofday (_TIME_GETCLOCK, &stop);
- printf("Stop tick count: %lu\n", stop);
- printf("-----------------\n");
- printf("Total ticks : %lu\n", stop - start);
- }
- /* End _bios_timeofday */
- #undef main
- /**** name=bsearch ****/
- #define main TEST_bsearch
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- struct info {
- char name[8];
- int age;
- char phone[9];
- };
-
- /* Array of info sorted by age, and then by name. */
- struct info data[] = {
- { "Alice", 19, "555-7979" },
- { "Fred", 27, "555-1221" },
- { "Frank", 30, "555-1965" },
- { "Carol", 32, "555-4299" },
- { "Anne", 33, "555-5552" },
- { "Larry", 33, "555-8235" },
- { "Sonya", 36, "555-1976" },
- };
- static int compare_function(const struct info *item1,
- const struct info *item2) {
- if (item1->age < item2->age) return (-1);
- else if (item1->age > item2->age) return (1);
- else return (strcmp(item1->name, item2->name));
- }
-
- struct info key = { "Carol", 32, "" };
-
- void main() {
- struct info *p;
- p = bsearch(&key,data,sizeof(data)/sizeof(*data),
- sizeof(*data), compare_function);
- if (p) printf("Name=%s, Age=%d, Phone=%s\n",
- p->name, p->age, p->phone);
- else printf("%s NOT FOUND\n", key.name);
- }
-
- /* End bsearch */
- #undef main
- /**** name=_cabs ****/
- #define main TEST__cabs
-
- #include <math.h>
-
- void main() {
- struct complex zz;
-
- zz.x = 5.0;
- zz.y = 7.0;
-
- printf("Complex absolute value of (5.0, 7.0i)"
- " is %f\n", _cabs(zz));
- }
-
- /* End _cabs */
- #undef main
- /**** name=calloc ****/
- #define main TEST_calloc
-
- /*
- The following example demonstrates calloc() in two different ways. In
- function f1(), calloc() initializes integers to zero. Next, f2() shows
- how calloc() initializes chars to NULL, and also illustrates the
- difference between calloc() and malloc().
- */
- #include <stdlib.h>
- #include <stdio.h>
- extern void f1();
- extern void f2();
-
- void main() {
- printf("\nEXAMPLE 1:\n");
- f1();
- printf("\nEXAMPLE 2:\n");
- f2();
- }
-
- void f1() {
- int i;
- typedef int grade;
- grade *grade_ptr;
-
- /* Allocate space for grades, setting them to 0. */
- grade_ptr = (int *) calloc (4, sizeof(grade));
- for (i = 0; i <= 3; i++)
- printf("Grade %d is initially %d.\n",
- i, grade_ptr[i]);
- }
-
- void f2() {
- typedef struct {
- char *first;
- char *last;
- } names ;
- names *name_ptr=(names *)calloc(1,sizeof(names));
- if (name_ptr == NULL)
- printf("Out of Memory!\n");
- else
- /* calloc initializes char to NULL */
- if (name_ptr->first == NULL)
- printf("calloc was used"
- " to allocate space.\n");
- else
- /* malloc does not; space contains garbage. */
-
- printf("malloc was used"
- " to allocate space.\n");
- }
-
- /* End calloc */
- #undef main
- /**** name=ceil ****/
- #define main TEST_ceil
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- double d = 2.789;
- printf("The number is %.2e\n", d);
- printf("ceil returned %.2e\n", ceil(d));
- }
-
- /* End ceil */
- #undef main
- /**** name=_cgets ****/
- #define main TEST__cgets
-
- #include <stdio.h>
-
- void main() {
- extern char *_cgets(char *bufr);
- char p[85];
- char *q;
-
- p[0] = 80;
- puts("Testing _cgets...\n");
- puts("Enter a line of text.");
- q = (_cgets(p));
- puts("The characters entered were:");
- puts(q);
- printf("\nThe entire buffer length in bytes is"
- " %d.\n",p[1]);
- }
-
- /* End _cgets */
- #undef main
- /**** name=_chdir ****/
- #define main TEST__chdir
-
- /*
- This program changes the current directory.
- */
- #include <stdio.h>
- #include <direct.h>
- void main() {
-
- if (_chdir("c:\\") == -1) /* Go to root directory. */
- perror("error in _chdir");
- else
- printf("Directory successfully"
- " changed to c:\\.\n");
- }
- /* End _chdir */
- #undef main
- /**** name=_chmod ****/
- #define main TEST__chmod
-
- /*
- This program alters the permission setting of a user-specified file.
- */
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <io.h>
- #include <stdio.h>
- #include <stdlib.h>
- void main() {
- char filename[50];
- int newmode;
-
- printf("Change permission setting of file: ");
- scanf("%s", filename);
- printf("\n1. read-only\n2. read/write\n");
- printf("Enter number of mode to change to:\n");
- scanf("%d", &newmode);
- switch (newmode) {
- case 1:
- if (_chmod(filename, S_IREAD) == -1)
- perror("File not found.");
- else
- printf("%s changed to read only \n",
- filename);
- break;
- case 2:
- if (_chmod(filename, S_IREAD | S_IWRITE) == -1)
- perror("File not found");
- else
- printf("%s changed to read/write \n",
- filename);
-
- }
- }
- /* End _chmod */
- #undef main
- /**** name=_chsize ****/
- #define main TEST__chsize
-
- /*
- The program opens/creates the file chsize.tmp. If the file has a write
- permission then it writes 512 bytes to the file and uses the function
- _chsize to change the size to 256 bytes. If the file chsize.tmp does
- not have write permission an appropriate message is printed.
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <io.h>
- #include <fcntl.h>
- #include <types.h>
- #include <stat.h>
- #include <errno.h>
- #define NEWSIZE 256L
-
- void main() {
- int handle;
- char buffer[BUFSIZE];
- char *filename = "chsize.tmp";
-
- puts("Testing _chsize...\n");
- /* Open new file. */
- if ((handle = _open(filename, O_RDWR | O_CREAT,
- S_IWRITE | S_IREAD)) > 0) {
- /* Check for write permission. */
- if (! access(filename,3)) {
- /* Write to the buffer. */
- memset(buffer, 'X', BUFSIZE);
- /* Write buffer to file. */
- _write(handle, buffer, BUFSIZE);
- printf("File %s is %Ld bytes long.\n",
- filename, filelength(handle));
-
- if (! _chsize(handle, NEWSIZE))
- printf("File %s is now %Ld bytes long.\n",
- filename, filelength(handle));
- else
- printf("ERROR _chsize was unsuccessful.\n");
- }
- else
- printf("ERROR: %s not WRITEABLE."
- "\n", filename);
- }
- else printf("Error occured in opening file. %s:"
- " ERROR NUMBER %d.\n", filename, errno);
- }
- /* End _chsize */
- #undef main
- #undef NEWSIZE
- /**** name=clock ****/
- #define main TEST_clock
- /* End clock */
- #undef main
- /**** name=CLOCKS_PER_SEC ****/
- #define main TEST_CLOCKS_PER_SEC
-
- /*
- This example sets up a real-world timer that uses the first command-line
- argument as a value for time.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- void main() {
- clock_t start = clock()/CLOCKS_PER_SEC;
- clock_t duration = 5;
-
- printf("Waiting for %ld seconds to pass.\n",
- (long) duration);
- while (((clock()/CLOCKS_PER_SEC) - start) <=
- duration)
- ;
- puts("Time elapsed.");
- }
-
- /* End CLOCKS_PER_SEC */
- #undef main
- /**** name=clock_t ****/
- #define main TEST_clock_t
- /* End clock_t */
- #undef main
- /**** name=_close ****/
- #define main TEST__close
-
- /*
- This program opens (creates new) and closes a file. It changes the
- permission of the file.
- */
-
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
-
- void main() {
- int fh, bad;
-
- puts("Testing _close...\n");
- fh = _open("close.tmp", O_CREAT | O_EXCL,
- _S_IWRITE | _S_IREAD);
- bad = _close(fh);
- if (bad == 0)
- puts("Created close.tmp, a zero-length file.");
- else
- puts("_close failed.");
- }
- /* End _close */
- #undef main
- /**** name=_compare ****/
- #define main TEST__compare
-
- /*
- This program tests the function _compare.
- */
-
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char String1[]="this is a test";
- char String2[]="that is a test";
- char String3[]="testing 1 2 3 ";
- char String4[]="";
- int i;
-
- puts("Testing _compare...\n");
- printf("String 1:%s,\tString 2:"
- "%s.\n",String1, String1);
- i = _compare(String1, String1, strlen(String1));
-
- if (i == 0)
- printf("Strings are equal. \n");
- else
- printf("Strings are not equal.\n");
- printf("Return is %d.\n\n",i);
-
- printf("String 1:%s,\tString 2:"
- "%s.\n",String2, String3);
- i = _compare(String2, String3, strlen(String3));
- if (i == 0)
- printf("Strings are equal. \n");
- else
- printf("Strings are not equal.\n");
- printf("Return is %d.\n\n",i);
-
- printf("String 1:%s,\tString 2:"
- "%s.\n",String4, String2);
- i = _compare(String4, String2, strlen(String2));
- if (i == 0)
- printf("Strings are equal. \n");
- else
- printf("Strings are not equal.\n");
-
- printf("Return is %d.\n",i);
- }
-
- /* End _compare */
- #undef main
- /**** name=cos ****/
- #define main TEST_cos
-
- /*
- This function shows the behavior of cos. Note that the argument to cos
- is in radians.
- */
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- printf("Cosine of 45 degrees (PI/4) = %f\n",
- cos(_PI/4));
- printf("Cosine of 90 degrees (PI/2) = %f\n",
- cos(_PI/2));
- }
- /* End cos */
- #undef main
- /**** name=cosh ****/
- #define main TEST_cosh
-
- /*
- This program tests the cosh function.
- */
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- printf("cosh(0.0) = %f.\n", cosh(0.0));
- printf("cosh(3.5) = %f.\n", cosh(3.5));
- /* Next, display the symmetry about y-axis. */
- printf("cosh(-3.5) = %f.\n", cosh(-3.5));
- }
- /* End cosh */
- #undef main
- /**** name=_cprintf ****/
- #define main TEST__cprintf
-
- /*
- The example for fprintf shows the similarity of the two functions.
- */
-
- #include <conio.h>
-
- void main() {
- char s[14] = "like this one", c = '*';
- int i = 10, x = 255, o = 45;
- double d = 3.1415927, nf = -3.449123;
- _cprintf("_cprintf prints strings (%s),\r\n", s);
- _cprintf("decimal numbers (%d),", i);
- _cprintf(" hex numbers (%04X),\r\n", x);
- _cprintf("floating-point numbers (%+.4e)\r\n", d);
- _cprintf("percent signs (%%),\r\n");
- _cprintf("characters (%-5c),\r\n", c);
- _cprintf("negative floating-points "
- "(% 010.2e),\r\n", nf);
- _cprintf("and even octal numbers (%-+#5o).", o);
- }
-
- /* End _cprintf */
- #undef main
- /**** name=_cputs ****/
- #define main TEST__cputs
-
- #include <conio.h>
-
- void main() {
- _cputs("This is a te");
- _cputs("st of the _cputs\nfunction.\r");
- }
-
- /* End _cputs */
- #undef main
- /**** name=_creat ****/
- #define main TEST__creat
-
- #include <io.h>
- #include <fcntl.h>
- #include <sys\stat.h>
- #include <stdio.h>
-
- void main() {
- int pan;
-
- pan=_creat("creat.tmp", S_IREAD | S_IWRITE);
- if (pan == -1)
- printf("Cannot creat/truncate file creat.tmp,"
- " error code=%d\n",pan);
- else
- printf("file creat.tmp has been"
- " creat/truncated,"
- " handle=%d\n",pan);
- }
-
- /* End _creat */
- #undef main
- /**** name=_crotX ****/
- #define main TEST__crotX
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main() {
- char k=1;
- char j=0x80;
-
- printf("Rotate left and right by"
- " one bit at a time\n");
- do {
- printf("%4x %4x\n", k, j);
- k = _crotl(k,1);
- j = _crotr(j,1);
- }
- while (k != 1);
- }
- /* End _crot* */
- #undef main
- /**** name=ctime ****/
- #define main TEST_ctime
-
- /*
- This example illustrates the use of ctime() with time().
- */
- #include <time.h>
- #include <stdio.h>
-
- void main() {
- time_t t;
-
- time(&t);
- printf("Time: %s", ctime(&t));
- }
- /* End ctime */
- #undef main
-
- /*****names*****/
-
- char * names[]={
- "abort",
- "abs",
- "_access",
- "_alloca",
- "asctime",
- "asin",
- "assert",
- "atan",
- "atan2",
- "atexit",
- "atof",
- "atoi",
- "atol",
- "_bdos",
- "_bios_disk",
- "_bios_equiplist",
- "_bios_keybrd",
- "_bios_memsize",
- "_bios_printer",
- "_bios_serialcom",
- "_bios_timeofday",
- "bsearch",
- "_cabs",
- "calloc",
- "ceil",
- "_cgets",
- "_chdir",
- "_chmod",
- "_chsize",
- "CLOCKS_PER_SEC",
- "_close",
- "_compare",
- "cos",
- "cosh",
- "_cprintf",
- "_cputs",
- "_creat",
- "_crotX",
- "ctime",
- "",""};
- int nextfunum;
- void main() {
- char ans[90];
- for (;;) {
- for (int j=0;j< 39;j++)
- if (j%3==2) printf("%4d %-21s\n",j+1,names[j]);
- else printf("%4d %-21s",j+1,names[j]);
- printf("\n\nPlease enter a number from the above list (enter=%d, exit=0): ",++nextfunum);
- gets(ans);
- if (ans[0] != 0) nextfunum=atoi(ans);
- printf("\n\n\n");
- switch(nextfunum) {
- case 0:exit(0);
- case 1:TEST_abort();break;
- case 2:TEST_abs();break;
- case 3:TEST__access();break;
- case 4:TEST__alloca();break;
- case 5:TEST_asctime();break;
- case 6:TEST_asin();break;
- case 7:TEST_assert();break;
- case 8:TEST_atan();break;
- case 9:TEST_atan2();break;
- case 10:TEST_atexit();break;
- case 11:TEST_atof();break;
- case 12:TEST_atoi();break;
- case 13:TEST_atol();break;
- case 14:TEST__bdos();break;
- case 15:TEST__bios_disk();break;
- case 16:TEST__bios_equiplist();break;
- case 17:TEST__bios_keybrd();break;
- case 18:TEST__bios_memsize();break;
- case 19:TEST__bios_printer();break;
- case 20:TEST__bios_serialcom();break;
- case 21:TEST__bios_timeofday();break;
- case 22:TEST_bsearch();break;
- case 23:TEST__cabs();break;
- case 24:TEST_calloc();break;
- case 25:TEST_ceil();break;
- case 26:TEST__cgets();break;
- case 27:TEST__chdir();break;
- case 28:TEST__chmod();break;
- case 29:TEST__chsize();break;
- case 30:TEST_CLOCKS_PER_SEC();break;
- case 31:TEST__close();break;
- case 32:TEST__compare();break;
- case 33:TEST_cos();break;
- case 34:TEST_cosh();break;
- case 35:TEST__cprintf();break;
- case 36:TEST__cputs();break;
- case 37:TEST__creat();break;
- case 38:TEST__crotX();break;
- case 39:TEST_ctime();break;
- default:printf("I don't recognize that answer\n");nextfunum=-1;break;
- }
- printf("\n\npress enter to select another function\n");
- gets(ans);
- }
- }
-