home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1990 MetaWare Incorporated; All Rights Reserved */
-
- /**** name=_inline ****/
- #define main TEST__inline
-
- #include <stdio.h>
- #define CLI _inline(0xfa)
- #define STI _inline(0xfb)
- int semaphor = 0;
-
- void main() {
- CLI; /* Disable interrupts. */
- semaphor++; /* Protect for reentrant usage. */
- STI; /* Enable interrupts. */
- puts("Multi-tasking semaphor is set.");
- }
- /* End _inline */
- #undef main
- #undef CLI
- #undef STI
- /**** name=_int86 ****/
- #define main TEST__int86
-
- /*
- Display all 256 character codes in normal, bold, and blink modes.
- */
-
- #include <dos.h>
- #include <stdio.h>
- void main() {
- int j, k, l, m;
- union REGS r;
-
- for (l = 0;l < 25; l++) puts(" ");
- l = 0;
- for (m = 0; m < 2; m++) {
- for (k = 0; k < 4; k++) {
- for (j = 0; j < 64; j++) {
- r.h.ah = 2;
- r.h.bh = 0;
- r.h.dh = k + m + m + m + m;
- r.h.dl = j;
- _int86(16, &r, &r);
- r.h.ah = 9;
- r.h.al = l++;
- r.h.bh = 0;
- r.h.bl = 128 + j + m * 128;
- r.x.cx = 1;
- _int86(16, &r, &r);
- }
- }
- }
- for (l=0;l<8;l++) puts(" ");
- }
- /* End _int86 */
- #undef main
- /**** name=_int86x ****/
- #define main TEST__int86x
-
- #include <stdio.h>
- #include <dos.h>
-
- void main() {
- union REGS r;
- struct SREGS s;
- /* Call is as documented in */
- /* The MS-DOS Encyclopedia on page 1242, */
- /* interrupt 21h function 0x1C. */
- r.h.ah = 0x1c;
- r.l.dl = 0;
- segread(&s);
- /* intdosx(&r, &r, &s); */
- _int86x(0x21, &r, &r, &s);
- printf("Number of sectors per cluster is"
- " %d\n", r.l.al);
- printf("Number of bytes per sector is"
- " %d\n", r.x.cx);
- printf("Number of clusters is"
- " %d\n", r.x.dx);
- printf("Address of file allocation table is"
- " %x:%x\n", s.ds, r.x.bx);
- }
-
- /* End _int86x */
- #undef main
- /**** name=_intdos ****/
- #define main TEST__intdos
-
- #include <dos.h>
- #include <stdio.h>
-
- void main() {
- union REGS r;
-
- r.h.ah = 0x33;
- r.l.al = 0;
- _intdos(&r, &r);
- printf("The Control-C flag was ");
- if (r.l.dl != 0)
- printf("on.\n");
- else {
- printf("off.\n");
- r.h.ah = 0x33;
- r.l.al = 1;
- r.l.dl = 1;
- _intdos(&r, &r);
- if (r.l.al != 255)
- printf("The Control-C flag is now on!\n");
- }
- }
-
- /* End _intdos */
- #undef main
- /**** name=isalnum ****/
- #define main TEST_isalnum
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
- if ((isalnum('A')) != 0)
- puts("A is alphanumeric.");
- else puts("A is not alphanumeric.");
-
- if ((isalnum('6')) != 0)
- puts("6 is alphanumeric.");
- else puts("6 is not alphanumeric.");
-
- if ((isalnum('!')) != 0)
- puts("! alphanumeric.");
- else puts("! is not alphanumeric.");
- }
-
- /* End isalnum */
- #undef main
- #undef True
- #undef False
- /**** name=isalpha ****/
- #define main TEST_isalpha
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
- if ((isalpha('+')) != 0)
- puts("+ is alphabetic.");
- else puts("+ is not alphabetic.");
- if ((isalpha('A')) != 0)
- puts("A is alphabetic.");
- else puts("A is not alphabetic.");
- }
-
- /* End isalpha */
- #undef main
- #undef True
- #undef False
- /**** name=_isascii ****/
- #define main TEST__isascii
-
- #include <stdio.h>
- #include <ctype.h>
- #define True (1)
- #define False (0)
-
- void main() {
- if ((_isascii(128)) != 0) /* ASCII codes are 0-127.*/
- puts("\\128 is ASCII.");
- else puts("\\128 is not ASCII.");
-
- if ((_isascii('~')) != 0)
- puts("~ is ASCII.");
- else puts("~ is not ASCII.");
-
- if ((_isascii(7)) != 0) /* 7 is the ASCII for bell.*/
- puts("Bell is ASCII.");
- else puts("Bell is not ASCII.");
- }
-
- /* End _isascii */
- #undef main
- #undef True
- #undef False
- /**** name=_isatty ****/
- #define main TEST__isatty
-
- /*
- This program determines if stdout is redirected. Run it with and
- without stdout redirected to observe the different results.
- */
-
- #include <stdio.h>
- #include <io.h>
-
- void main() {
-
- (_isatty(fileno(stdout))) ?
- puts("stdout is not redirected") :
- puts("stdout is redirected");
- }
-
- /* End _isatty */
- #undef main
- /**** name=iscntrl ****/
- #define main TEST_iscntrl
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if ((iscntrl('\12')) != 0)
- puts("\\12 is control.");
- else puts("\\12 is not control.");
- if ((iscntrl('$')) != 0)
- puts("$ is control.");
- else puts("$ is not control.");
- }
- /* End iscntrl */
- #undef main
- /**** name=isdigit ****/
- #define main TEST_isdigit
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if ((isdigit('&')) != 0)
- puts("& is a digit.");
- else puts("& is not a digit.");
- if ((isdigit('5')) != 0)
- puts("5 is a digit.");
- else puts("5 is not a digit.");
- }
- /* End isdigit */
- #undef main
- /**** name=isgraph ****/
- #define main TEST_isgraph
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if ((isgraph(7)) != 0)
- puts("Bell is a printable character.");
- else puts("Bell is not a printable character.");
- if ((isgraph(']')) != 0)
- puts("] is a printable character.");
- else puts("] is not a printable character.");
- if ((isgraph(' ')) != 0)
- puts("Space is a printable character.");
- else puts("Space is not a printable character.");
- }
-
- /* End isgraph */
- #undef main
- /**** name=islower ****/
- #define main TEST_islower
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if(islower('A') != 0)
- puts("A is lowercase.");
- else puts("A is not lowercase.");
-
- if(islower('a') != 0)
- puts("a is lowercase.");
- else puts("a is not lowercase.");
- }
- /* End islower */
- #undef main
- /**** name=_isodigit ****/
- #define main TEST__isodigit
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if ((_isodigit('a')) != 0)
- puts("a is octal.");
- else puts("a is not octal.");
- if ((_isodigit('8')) != 0)
- puts("8 is octal.");
- else puts("8 is not octal.");
- if ((_isodigit('7')) != 0)
- puts("7 is octal.");
- else puts("7 is not octal.");
- }
- /* End _isodigit */
- #undef main
- /**** name=isprint ****/
- #define main TEST_isprint
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if (isprint('0') != 0)
- puts("0 is printable.");
- else puts("0 is not printable.");
- if (isprint(' ') != 0)
- puts("space is printable.");
- else puts("space is not printable.");
- if (isprint('\t') != 0)
- puts("tab is printable.");
- else puts("tab is not printable.");
- if (isprint('D') != 0)
- puts("D is printable.");
- else puts("D is not printable.");
- }
-
- /* End isprint */
- #undef main
- /**** name=ispunct ****/
- #define main TEST_ispunct
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if (ispunct('X') != 0)
- puts("X is punctuation.");
- else puts("X is not punctuation.");
- if (ispunct(' ') != 0)
- puts("space is punctuation.");
- else puts("space is not punctuation.");
- if (ispunct('!') != 0)
- puts("! is punctuation.");
- else puts("! is not punctuation.");
- }
-
- /* End ispunct */
- #undef main
- /**** name=isspace ****/
- #define main TEST_isspace
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if (isspace('\t') != 0)
- puts("\\t is whitespace.");
- else puts("\\t is not whitespace.");
- if (isspace(' ') != 0)
- puts("space is whitespace.");
- else puts("space is not whitespace.");
- if (isspace('R') != 0)
- puts("R is whitespace.");
- else puts("R is not whitespace.");
- if (isspace('\7') != 0)
- puts("Bell is whitespace.");
- else puts("Bell is not whitespace.");
- }
- /* End isspace */
- #undef main
- /**** name=isupper ****/
- #define main TEST_isupper
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- if(isupper('A') != 0)
- puts("A is uppercase.");
- else puts("A is not uppercase.");
-
- if(isupper('a') != 0)
- puts("a is uppercase.");
- else puts("a is not uppercase.");
- }
- /* End isupper */
- #undef main
- /**** name=isxdigit ****/
- #define main TEST_isxdigit
-
- #include <stdio.h>
- #include <ctype.h>
-
- void main() {
- puts("Testing isxdigit...\n");
- if ((isxdigit('0')) > 0)
- puts("0 is a hexdigit.");
- else puts("0 is not a hexdigit.");
- if ((isxdigit('g')) > 0)
- puts("g is a hexdigit.");
- else puts("g is not a hexdigit.");
- if ((isxdigit('A')) > 0)
- puts("A is a hexdigit.");
- else puts("A is not a hexdigit.");
- }
-
- /* End isxdigit */
- #undef main
- /**** name=_itoa ****/
- #define main TEST__itoa
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char s[35],t[35];
- int j;
-
- for (j=1;j != 0;) { /* Forever, until zero. */
- puts("Enter a number (ZERO to quit)");
- gets(s); /* Get a number. */
- j=atoi(&s[0]); /* Convert it to integer. */
- puts(_itoa(j,t,10)); /* Display it in decimal. */
- puts(t); /* Display it again. */
- puts(_itoa(j,t,2)); /* Display it in binary. */
- puts(_itoa(j,t,16)); /* Display it in hex. */
- puts(_itoa(j,t,36)); /* Display it in base 36. */
- }
- }
-
- /* End _itoa */
- #undef main
- /**** name=jmp_buf ****/
- #define main TEST_jmp_buf
- /* End jmp_buf */
- #undef main
- /**** name=_kbhit ****/
- #define main TEST__kbhit
-
- #include <conio.h>
- void main() {
- puts("Testing hardware for a malfunctioning ");
- puts("cheap chip somewhere on the motherboard. ");
- puts("If this routine is interrupted, the machine ");
- puts("will self-destruct in a cloud of smoke. ");
- puts("So, please");
- puts(" *** don't touch the keyboard... ***\n");
- while (!_kbhit()) ; /* Do nothing. */
- puts("I told you not to touch the keyboard. ");
- puts("Now your machine will be "
- "\02\04\07\012\014\017\021\025\026\027\021\022\021\023");
- }
-
- /* End _kbhit */
- #undef main
- /**** name=labs ****/
- #define main TEST_labs
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- long absolut, posneg = -25412735;
-
- absolut = labs(posneg);
- printf("The absolute value of %ld is: %ld\n",
- posneg, absolut);
- }
- /* End labs */
- #undef main
- /**** name=ldexp ****/
- #define main TEST_ldexp
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- double x = 2.0, result;
- int exp = 5;
-
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- x = 3.0;
- exp = -3;
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- x = 5.0;
- exp = 0;
- result = ldexp(x , exp);
- printf("x = %.2f, exp = %d,\tResult =>"
- " %.2f\n",x,exp,result);
- }
-
- /* End ldexp */
- #undef main
- /**** name=ldiv ****/
- #define main TEST_ldiv
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main (){
- ldiv_t result;
- long i = 25429712, j = 101347;
- result = ldiv(i, j);
- printf("Numerator = %ld\n"
- "Denominator = %ld\n", i, j);
- printf("Result: Quotient = %ld\n"
- " Remainder = %ld\n",
- result.quot, result.rem);
- }
- /* End ldiv */
- #undef main
- /**** name=_lfind_lsearch ****/
- #define main TEST__lfind_lsearch
-
- #include <search.h>
- #include <string.h>
- #include <stdio.h>
-
- /* This function uses stricmp to make a case insensitive search. */
- int compr(const char *a, const char *b) {
- return(stricmp(*(char **)a, b));
- }
-
- void main() {
- char *data[11] = {"alice",
- "fred",
- "frank",
- "carol",
- "anne",
- "larry",
- "becky"};
- unsigned kount = 7;
- char **answer;
- char *key = "Carol";
-
- answer =
- (char **)_lfind(key, (char *)data,
- &kount, sizeof(char *), compr);
-
- if(answer)
- printf("Found: %s.\n", *answer);
- else
- printf("No match found for %s.\n", key);
- }
- /* End _lfind, _lsearch */
- #undef main
- /**** name=__LINE__ ****/
- #define main TEST___LINE__
-
- /*
- This code is contained in file in.c.
- */
-
- #include <stdio.h>
-
- void main() {
- printf("Hello from file %s, line %d.\n",
- __FILE__, __LINE__);
- }
-
- /* End __LINE__ */
- #undef main
- /**** name=localeconv ****/
- #define main TEST_localeconv
-
- #include <locale.h>
- #include <stdio.h>
-
- void main() {
- struct lconv *loc;
-
- loc = localeconv();
- printf("decimal point =>%s\n",loc->decimal_point);
- printf("thousands sep =>%s\n",loc->thousands_sep);
- printf("currency symbol =>%s\n",loc->currency_symbol);
- }
- /* End localeconv */
- #undef main
- /**** name=localtime ****/
- #define main TEST_localtime
- /* End localtime */
- #undef main
- /**** name=_locking ****/
- #define main TEST__locking
-
- #include <io.h>
- #include <fcntl.h>
- #include <stat.h>
- #include <locking.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main() {
- int pan;
- char c;
-
- pan = _open("test.dat",O_RDONLY|O_BINARY);
- if (pan != -1) {
- printf("File test.dat exists,"
- " handle = %d.\n",pan);
- if (0 != _locking(pan,LK_LOCK,50l))
- printf("_locking failed.\n");
- while(_read(pan, &c, 1) > 0)
- _putch(c);
- _lseek(pan, 0l, SEEK_SET);
- if (0 != _locking(pan, LK_UNLCK, 50l))
- printf("Unlocking failed.\n");
- }
- else
- printf("File test.dat cannot be opened,"
- " error code = %d.\n",pan);
- }
- /* End _locking */
- #undef main
- /**** name=log ****/
- #define main TEST_log
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- puts("Testing log...\n");
- printf("log(100.0) = %lf.\n",log(100.0));
- printf("log(10.0) = %lf.\n",log(10.0));
- printf("log(256.1) = %lf.\n",log(256.1));
- printf("log(2.718281828) = %lf.\n",
- log(2.718281828));
- }
- /* End log */
- #undef main
- /**** name=log10 ****/
- #define main TEST_log10
-
- #include <math.h>
- #include <stdio.h>
-
- void main() {
- puts("Testing log10...\n");
- printf("log10(100.0) = %lf.\n",log10(100.0));
- printf("log10(10.0) = %lf.\n",log10(10.0));
- printf("log10(256.1) = %lf.\n",log10(256.1));
- printf("log10(2.718281828) = %lf.\n",
- log10(2.718281828));
- }
-
- /* End log10 */
- #undef main
- /**** name=longjmp ****/
- #define main TEST_longjmp
-
- /*
- This example illustrates the use of longjmp and setjmp.
- */
- #include <stdio.h>
- #include <setjmp.h>
- #define RETURN 1
- #define FAIL (-1)
- jmp_buf jump_buffer;
- void process();
-
- void main(void) {
- int Flag = 0;
- printf("Initializing process...\n");
- /* Return to this point when
- longjmp is called. */
- Flag = setjmp(jump_buffer);
- if (Flag != RETURN) process();
- printf("Ending program.\n");
- }
-
- int setvar(void);
- void process(void) {
- printf("Beginning processing...\n");
- /* There's processing being skipped here.
-
- Assume that things have happened. */
- if(setvar() == FAIL) {
- printf("Something failed! Bailing out.\n");
- longjmp(jump_buffer, RETURN);
- }
- /* More processing could take place here if
- setvar() didn't return FAIL. */
- }
-
- int setvar(void) {
- return FAIL;
- }
- /* End longjmp */
- #undef main
- #undef RETURN
- #undef FAIL
- /**** name=_lrotX ****/
- #define main TEST__lrotX
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main() {
- long int k1=1;
- long int k7=1;
- long int k8=1;
- long int k9=1;
- long int k15=1;
- long int k17=1;
- printf("Rotate bits left by\n one 7"
- " 8 9 15 17\n");
- do {
- printf("%8lx %8lx %8lx %8lx %8lx %8lx\n",
- k1, k7, k8, k9, k15, k17);
- k1=_lrotl(k1,1);
- k7=_lrotl(k7,7);
-
- k8=_lrotl(k8,8);
- k9=_lrotl(k9,9);
- k15=_lrotl(k15,15);
- k17=_lrotl(k17,17);
- } while (k1!=1);
- }
-
- /* End _lrot* */
- #undef main
- /**** name=_lseek ****/
- #define main TEST__lseek
-
- #include <io.h>
- #include <fcntl.h>
- #include <sys\stat.h>
- #include <stdio.h>
- #include <conio.h>
-
- void main() {
- char c;
- int pan;
- long int k;
-
- pan = open("test.dat", O_RDONLY | O_BINARY);
- if (pan != -1) {
- printf("File test.dat exists,"
- " handle = %d.\n", pan);
- /* Start read before the end of file. */
- k = _lseek(pan, -1l, SEEK_END);
- while ((k = _lseek(pan,--k,SEEK_SET)) != -1l) {
- read(pan, &c, 1);
- printf("%c", c);
- }
- }
- else
- printf("File test.dat cannot be opened,"
- " error code = %d.\n", pan);
- }
-
- /* End _lseek */
- #undef main
- /**** name=L_tmpnam ****/
- #define main TEST_L_tmpnam
- /* End L_tmpnam */
- #undef main
- /**** name=_ltoa ****/
- #define main TEST__ltoa
-
- #include <stdlib.h>
- #include <stdio.h>
-
- void main() {
- char s[55], t[55];
- long int j;
-
- for(j = 1;j != 0;) {
- puts("Enter a number, (ZERO to quit)");
- gets(s);
- j = atol(s);
- printf("The number you entered is: %ld\n"
- "And in base 10, 10, 2, 16 and 36"
- " it is\n", j);
- puts(_ltoa(j, t, 10));
- puts(t);
-
- puts(_ltoa(j, t, 2));
- puts(_ltoa(j, t, 16));
- puts(_ltoa(j, t, 36));
- }
- }
-
- /* End _ltoa */
- #undef main
- /**** name=_makepath ****/
- #define main TEST__makepath
-
- /*
- This program constructs a full pathname from specified components.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char buffer[67];
- char *drive = "c";
- char *dir = "highc\\inc";
- char *fname = "stdio";
- char *ext = "h";
-
- _makepath(buffer, drive, dir, fname, ext);
- printf("Path created with _makepath: %s\n\n",
- buffer);
- }
-
- /* End _makepath */
- #undef main
- /**** name=malloc ****/
- #define main TEST_malloc
-
- /*
- This example demonstrates how to use malloc to allocate uninitialized
- storage.
- */
- #include <stdlib.h>
-
- void main() {
- char *name_ptr;
-
- /* Set aside 20 bytes for a character array. */
- name_ptr = (char *) malloc(20 * sizeof(char));
-
- if (name_ptr == NULL) printf("Out of Memory!\n");
- else printf("malloc was used to allocate space.\n");
- }
- /* End malloc */
- #undef main
- /**** name=_max_min ****/
- #define main TEST__max_min
-
- /*
- This program tests the min and max functions.
- */
- float f;
- unsigned long ul;
- int i;
-
- void main() {
- float r1;
- unsigned long r2;
- f=20.0;
- ul=29;
- i=10;
-
- puts("Testing _min & _max...\n");
- printf("Output of _min.\n");
- r1 = _min(f, ul, i); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
-
- r2 = _min(ul, i); /* Has type unsigned long int. */
- printf("r2 ==> %u.\n",r2);
- r1 = _min(i, f); /* Has type float. */
- printf("r1 ==> %.1f.\n\n",r1);
-
- printf("output of _max.\n");
- r1 = _max(f, ul, i); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
- r2 = _max(ul, i); /* Has type unsigned long int. */
- printf("r2 ==> %u.\n",r2);
- r1 = _max(i, f); /* Has type float. */
- printf("r1 ==> %.1f.\n",r1);
- }
- /* End _max, _min */
- #undef main
- /**** name=_memccpy ****/
- #define main TEST__memccpy
-
- #include <memory.h>
- #include <stdio.h>
-
- void main() {
- char a[] =
- "This is a test!! of _memccpy - ignore this";
- char x[100] = "this data will disappear";
- char *b, *c;
- b = &x[0];
- c = _memccpy(b, a, '-', 50);
- *(c + 15) = 0;
- c = _memccpy(c, a, '-', 15);
- /* x[41] = 0; */
- puts(x);
- }
-
- /* End _memccpy */
- #undef main
- /**** name=memchr ****/
- #define main TEST_memchr
-
- /*
- This program uses memchr to find the position of the letter S.
- */
- #include <stddef.h>
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char *targ = "Sea Shells by the Sea Shore.";
- char *pntr;
- char find = 'S';
- int len;
-
- len = strlen(targ);
- printf("Search the string '%s'\nfor"
- " the character '%c'\n",targ,find);
- for (pntr = targ;;pntr++) {
- pntr = memchr(pntr, find, len);
- if(pntr == NULL)
- break;
- printf("There is an '%c' at position %d.\n",
- find,pntr-targ);
- }
- }
- /* End memchr */
- #undef main
- /**** name=memcmp ****/
- #define main TEST_memcmp
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char s1[] = "This is testing 1 2 3 4 5";
- char s2[] = "This is testing 1 2 3 4 5 6";
- int res;
- size_t len=0;
-
- puts("Testing memcmp...\n");
- printf("Comparing Strings:\n1: '%s' and\n2:"
- " '%.25s'\n", s1, s2);
- len = strlen(s1);
- res = (memcmp(s1, s2, len));
- if (res == 0)
- printf("s1 is equal to s2.\n\n");
- else if (res < 0)
- printf("s1 is less than s2.\n\n");
- else
- printf("s1 is greater than s2.\n\n");
- printf("Comparing Strings:\n1: '%s' and\n2:"
- " '%s'\n", s1, s2);
- len = strlen(s2);
- res = (memcmp(s1, s2, len));
- if (res < 0)
- printf("s1 is less than s2.\n\n");
- else if (res > 0)
- printf("s1 is greater than s2.\n\n");
- else
- printf("s1 is equal to s2.\n\n");
- }
- /* End memcmp */
- #undef main
- /**** name=memcpy ****/
- #define main TEST_memcpy
-
- /*
- This example uses memcpy to copy the contents of an array of ints to
- another array.
- */
- #include <string.h>
- #include <stdio.h>
- void disp_ints();
- void main() {
- int i[5] = {1, 2, 3, 4, 5};
- int j[5] = {0, 0, 0, 0, 0};
-
- disp_ints(&i, &j);
- memcpy(&j, &i, sizeof(j));
- disp_ints(&i, &j);
- }
-
- void disp_ints(int *i, int *j) {
- int c;
-
- printf("\ni =>");
-
- for(c = 0; c < 5; c++)
- printf(" %d", i[c]);
- printf("\nj =>");
- for(c = 0; c < 5; c++)
- printf(" %d", j[c]);
- }
- /* End memcpy */
- #undef main
- /**** name=_memicmp ****/
- #define main TEST__memicmp
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] ="tHIS iS a tEST Z1";
- char b[] ="This Is A Test z2";
- char aa[] ="tHIS iS a tEST ZA1";
- char bb[] ="This Is A Test za2";
- char c[] ="[]";
- char d[] ="{}";
- char e[] ="1234";
- char f[] ="5678";
-
- if (memicmp(a,b,(size_t)16)==0)
- puts("memicmp equal test ok");
- else puts("memicmp equal test failed");
- if (memicmp(c,d,(size_t)2)==0)
- puts("memicmp unequal test failed");
- else puts("memicmp unequal test ok");
- if (memicmp(e,e,(size_t)4)==0)
- puts("memicmp equal2 test ok");
- else puts("memicmp equal2 test failed");
- if (memicmp(e,f,(size_t)4)==0)
- puts("memicmp unequal test failed");
- else puts("memicmp unequal test ok");
- if (memicmp(a,b,(size_t)17)==0)
- puts("memicmp equal3 test failed");
- else puts("memicmp equal3 test ok");
- if (memicmp(a,b,(size_t)18)==0)
- puts("memicmp equal4 test failed");
- else puts("memicmp equal4 test ok");
- if (memicmp(aa,bb,(size_t)17)==0)
- puts("memicmp equal5 test ok");
- else puts("memicmp equal5 test failed");
- }
-
- /* End _memicmp */
- #undef main
- /**** name=memset ****/
- #define main TEST_memset
-
- #include <stdio.h>
- #include <string.h>
-
- void strip (char *s1, char *s2) {
- int i;
- while (*s1 != 0) { /* Not the end of s1, so: */
- /* Set s1 to point at the first character */
- /* from s1 that is not in s2. */
- s1 += strspn(s1, s2);
- /* Set i to the length of the prefix of s1 */
- /* containing no characters from s2. */
- /* Write NUL on each such character. */
- memset(s1, 0, i = strcspn(s1, s2));
- /* Set s1 to point at the character after */
- /* the last NUL just written. */
- s1 += i;
- }
- }
-
- void main() {
- char *s1 =
- "Those funny char's are leaving! --->!#$";
- char *s2 = "Those funny char's are leaving!";
-
- puts(s1);
- strip(s1, s2);
- puts(s1);
- }
-
- /* End memset */
- #undef main
- /**** name=_mkdir ****/
- #define main TEST__mkdir
-
- /*
- This program makes a directory.
- */
-
- #include <stdio.h>
- #include <direct.h>
- #include <time.h>
-
- void main() {
- /* create a new directory */
- char a[20]="c:\\";
- _strtime(&a[3]);
- a[5]='-';
- a[8]='-';
- if (_mkdir(a) == -1)
- perror("error in _mkdir");
- else
- printf("directory %s successfully created.\n",a);
- }
- /* End _mkdir */
- #undef main
- /**** name=_mktemp ****/
- #define main TEST__mktemp
-
- /*
- This program calls _mktemp to get a unique file name, then opens the
- file with a call to fopen.
- */
-
- #include <stdio.h>
- #include <process.h>
- #include <io.h>
-
- FILE *stream1, *stream2;
- char *tempname;
-
- void main() {
- if ((tempname = _mktemp("myXXXXXX")) == NULL)
- printf("_mktemp failed on file 1\n");
- else {
- stream1 = fopen(tempname, "w");
- printf("Opened temp file %s\n", tempname);
-
- if ((tempname = _mktemp("myXXXXXX")) == NULL)
- printf("_mktemp failed on file 2\n");
- else {
- stream2 = fopen(tempname, "w");
- printf("Opened temp file %s\n", tempname);
- fclose(stream2);
- }
- fclose(stream1);
- }
- }
- /* End _mktemp */
- #undef main
- /**** name=mktime ****/
- #define main TEST_mktime
-
- #include <stdio.h>
- #include <time.h>
-
- void main() {
- time_t t;
- struct tm *p;
-
- time(&t);
- p = localtime(&t);
- printf("The time is %ld.\n", mktime(p));
- }
- /* End mktime */
- #undef main
- /**** name=modf ****/
- #define main TEST_modf
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- double x, i;
-
- x = modf(2.4, &i);
- printf("%e %e", x, i);
- }
-
- /* End modf */
- #undef main
- /**** name=_move ****/
- #define main TEST__move
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char array1[40] =
- " QRSTUVWXYZ";
- char array2[40] =
- "1234567890abcdefghijklmnopqrstuvwxyz";
- char *dest = &array2[0], *source = array1;
- int i;
-
- _move (dest, source, 26);
- puts("Array 2 is moved into Array 1.");
- puts("Now Array 1 looks like this:");
- for (i = 0; i <= 37; i++)
- putchar(array1[i]);
- printf("\n");
- }
- /* End _move */
- #undef main
- /**** name=_movedata ****/
- #define main TEST__movedata
-
- #include <memory.h>
- void main() {
- unsigned int scrn;
-
- for (scrn = 1;scrn<21;scrn++)
- printf("This is screen line %d.\n"
- " %*s%*s",scrn,scrn," ",scrn," ");
-
- if(sizeof(int) == 2)
- scrn = 0xb000;
- else
- scrn = 0x1c; /* 386 protected mode. */
- _movedata(scrn, 0, scrn, 80 * 24, 80 * 12);
- }
- /* End _movedata */
- #undef main
- /**** name=_nfree ****/
- #define main TEST__nfree
-
- #include <stdio.h>
- #include <malloc.h>
-
- void main() {
- char *new_array;
- new_array = _nmalloc (5000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("nfree: Not enough memory"
- " for 5,000 longs\n");
- }
- else {
- printf("nfree: Allocated 5,000 longs at %x \n",
- new_array);
- printf("nfree: Dellocating memory block at %x \n",
- new_array);
- _nfree(new_array);
- }
- }
-
- /* End _nfree */
- #undef main
- /**** name=_nmalloc ****/
- #define main TEST__nmalloc
-
- #include <stdio.h>
- #include <malloc.h>
-
- void main() {
- char *new_array;
-
- new_array = _nmalloc(15000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("_nmalloc: Not enough memory"
- " for 15,000 longs\n");
- new_array = _nmalloc(5000 * sizeof(long));
-
- if (new_array == NULL) {
- printf("_nmalloc: Not enough memory"
- " for 5,000 longs.\n");
- }
- else {
- printf("_nmalloc: Allocated 5000 longs"
- " at %lx \n", new_array);
- }
- }
- else
- printf("_nmalloc: Allocated 15,000 longs"
- " at %lx \n", new_array);
- }
-
- /* End _nmalloc */
- #undef main
-
- /*****names*****/
-
- char * names[]={
- "_inline",
- "_int86",
- "_int86x",
- "_intdos",
- "isalnum",
- "isalpha",
- "_isascii",
- "_isatty",
- "iscntrl",
- "isdigit",
- "isgraph",
- "islower",
- "_isodigit",
- "isprint",
- "ispunct",
- "isspace",
- "isupper",
- "isxdigit",
- "_itoa",
- "_kbhit",
- "labs",
- "ldexp",
- "ldiv",
- "_lfind_lsearch",
- "__LINE__",
- "localeconv",
- "_locking",
- "log",
- "log10",
- "longjmp",
- "_lrotX",
- "_lseek",
- "_ltoa",
- "_makepath",
- "malloc",
- "_max_min",
- "_memccpy",
- "memchr",
- "memcmp",
- "memcpy",
- "_memicmp",
- "memset",
- "_mkdir",
- "_mktemp",
- "mktime",
- "modf",
- "_move",
- "_movedata",
- "_nfree",
- "_nmalloc",
- "",""};
- int nextfunum;
- void main() {
- char ans[90];
- for (;;) {
- for (int j=0;j< 50;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__inline();break;
- case 2:TEST__int86();break;
- case 3:TEST__int86x();break;
- case 4:TEST__intdos();break;
- case 5:TEST_isalnum();break;
- case 6:TEST_isalpha();break;
- case 7:TEST__isascii();break;
- case 8:TEST__isatty();break;
- case 9:TEST_iscntrl();break;
- case 10:TEST_isdigit();break;
- case 11:TEST_isgraph();break;
- case 12:TEST_islower();break;
- case 13:TEST__isodigit();break;
- case 14:TEST_isprint();break;
- case 15:TEST_ispunct();break;
- case 16:TEST_isspace();break;
- case 17:TEST_isupper();break;
- case 18:TEST_isxdigit();break;
- case 19:TEST__itoa();break;
- case 20:TEST__kbhit();break;
- case 21:TEST_labs();break;
- case 22:TEST_ldexp();break;
- case 23:TEST_ldiv();break;
- case 24:TEST__lfind_lsearch();break;
- case 25:TEST___LINE__();break;
- case 26:TEST_localeconv();break;
- case 27:TEST__locking();break;
- case 28:TEST_log();break;
- case 29:TEST_log10();break;
- case 30:TEST_longjmp();break;
- case 31:TEST__lrotX();break;
- case 32:TEST__lseek();break;
- case 33:TEST__ltoa();break;
- case 34:TEST__makepath();break;
- case 35:TEST_malloc();break;
- case 36:TEST__max_min();break;
- case 37:TEST__memccpy();break;
- case 38:TEST_memchr();break;
- case 39:TEST_memcmp();break;
- case 40:TEST_memcpy();break;
- case 41:TEST__memicmp();break;
- case 42:TEST_memset();break;
- case 43:TEST__mkdir();break;
- case 44:TEST__mktemp();break;
- case 45:TEST_mktime();break;
- case 46:TEST_modf();break;
- case 47:TEST__move();break;
- case 48:TEST__movedata();break;
- case 49:TEST__nfree();break;
- case 50:TEST__nmalloc();break;
- default:printf("I don't recognize that answer\n");nextfunum=-1;break;
- }
- printf("\n\npress enter to select another function\n");
- gets(ans);
- }
- }
-