home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1990 MetaWare Incorporated; All Rights Reserved */
-
- /**** name=scanf ****/
- #define main TEST_scanf
-
- /*
- This example shows how to use scanf to get a string from the keyboard.
- */
-
- #include <stdio.h>
-
- void main() {
- char name[128];
-
- printf("Please enter your first name> ");
- scanf("%s", name);
- printf("Thank you, %s.\n", name);
- }
- /* End scanf */
- #undef main
- /**** name=_searchenv ****/
- #define main TEST__searchenv
-
- /*
- This program searches for the location of file stdio.h using the IPATH
- environment variable.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
-
- void main() {
- char buffer[128];
-
- _searchenv("stdio.h", "IPATH", buffer);
- if (strcmp(buffer, "") == 0)
- puts("File not found.\n");
- else
- printf("The file stdio.h is in directory:"
- " %s.\n", buffer);
- }
- /* End _searchenv */
- #undef main
- /**** name=_segread ****/
- #define main TEST__segread
-
- /*
- This program displays the current values of the segment registers.
- */
-
- #include <stdio.h>
- #include <dos.h>
-
- void main() {
- struct SREGS segs;
-
- _segread(&segs);
- printf("Current values of segment registers:\n"
- "code segment: %x\ndata segment: %x\n"
- "extra segment: %x\nstack segment: %x\n",
- segs.cs, segs.ds, segs.es, segs.ss);
- }
- /* End _segread */
- #undef main
- /**** name=setjmp ****/
- #define main TEST_setjmp
- /* End setjmp */
- #undef main
- /**** name=_setmode ****/
- #define main TEST__setmode
-
-
- /*
- The program below copies a line from standard
- input to standard output without doing any text
- conversions.
- */
-
- #include <stdio.h>
-
- void main() {
- char line[256];
-
- _setmode(stdin, _BINARY);
- _setmode(stdout, _BINARY);
-
- printf("\nPlease enter a line of text: ");
- if (gets(line))
- puts(line);
- _setmode(stdin, _TEXT);
- _setmode(stdout, _TEXT);
- }
- /* End _setmode */
- #undef main
- /**** name=_setpvect ****/
- #define main TEST__setpvect
- /* End _setpvect */
- #undef main
- /**** name=_setrpvectp ****/
- #define main TEST__setrpvectp
-
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- int Num_Ctrl_Cs = 0;
-
- _Far void _INTERRPT handler(void) {
- Num_Ctrl_Cs++;
- return;
- }
-
- void main(void) {
- int i, intno = 0x23; /* 0x23 is the Control-C interrupt. */
- _real_int_handler_t saver;
- _Far _INTERRPT void (* savep)() = (_Far) NULL;
-
- saver = _getrvect(intno); /* Get original vectors. */
- savep = _getpvect(intno);
-
- /*
-
- Set both vectors to point to protected-mode handler.
- */
-
- if(_setrpvectp(intno, handler) == -1 ) {
- fprintf(stderr, "Failed to install handler\n");
- return;
- }
-
- printf("Hit Control-C for a little while.\n");
- for(i = 0; i < 5000; i++)
- printf("\r%5d", i);
- printf("Number of Control C's = %d.\n", Num_Ctrl_Cs);
-
- /* Restore real-mode handler. */
- if(_setrvect(intno, saver) == -1 ) {
- fprintf(stderr, "Failed to restore"
- " real-mode handler.\n");
- return;
- }
-
- /* Restore protected-mode handler. */
- if(_setpvect(intno, savep) == -1 ) {
- fprintf(stderr, "Failed to restore"
- " protected-mode handler.\n");
- return;
- }
- return;
- }
- /* End _setrpvectp */
- #undef main
- /**** name=_setrvect ****/
- #define main TEST__setrvect
- /* End _setrvect */
- #undef main
- /**** name=setvbuf ****/
- #define main TEST_setvbuf
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char buffer[256];
- size_t size = sizeof(buffer);
- FILE *FP1, *FP2;
-
- if ((FP1 = fopen("setvbuf1.tmp","a")) == NULL)
- printf("Unable to open setvbuf1.tmp.\n");
- if (setvbuf(FP1,buffer,_IOFBF,size) != 0)
- printf("setvbuf failed on setvbuf1.tmp\n");
- else
- printf("setvbuf was successful.\n");
- fclose(FP1);
-
- if ((FP2 = fopen("setvbuf2.tmp","w")) == NULL)
- printf("Unable to open setvbuf2.tmp.\n");
- if (setvbuf(FP2,NULL,_IONBF,0) != 0)
- printf("setvbuf failed on setvbuf2.tmp\n");
- else
- printf("setvbuf was successful.\n");
- fclose(FP2);
- }
- /* End setvbuf */
- #undef main
- /**** name=signal ****/
- #define main TEST_signal
-
- #include <signal.h>
- #include <stdio.h>
-
- int ctlcflag = 1;
-
- void main(){
- extern void func(int);
-
- signal(SIGINT, &func);
- for (int i = 0; i < 100000; i++)
- if (!(i % 1000))
- printf( "%d ", i );
- if (ctlcflag) printf( "You did not hit CTRL-c\n" );
- }
-
- void func(int x){
- printf("You hit CTRL-c\n");
- ctlcflag = 0;
- return;
- }
- /* End signal */
- #undef main
- /**** name=sin ****/
- #define main TEST_sin
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- double x;
- int i;
-
- for(i = 0; i < 4; i++) {
- x = sin(i * _PI / 4);
- printf("sin of %d * pi / 4 = %lf\n", i, x);
- }
- }
- /* End sin */
- #undef main
- /**** name=sinh ****/
- #define main TEST_sinh
-
- #include <stdio.h>
- #include <math.h>
-
- void main() {
- double x, y;
-
- for(y = 0.0; y < 4.0; y += 1.0) {
- x = sinh(y);
- printf("sinh of %.1lf = %lf\n", y, x);
- }
- }
- /* End sinh */
- #undef main
- /**** name=_skip_char ****/
- #define main TEST__skip_char
-
- #include <stdio.h>
-
- void main() {
- char p[10] = "TESTING.";
- char q[10] = "NNNNNNT.";
- unsigned sl = 10, n, m;
- char c = 'T';
- char d = 'N';
-
- n=_skip_char(p, sl, c);
- m=_skip_char(q, sl, d);
- printf("n = %u, m = %u\n", n, m);
- }
-
- /* End _skip_char */
- #undef main
- /**** name=_sopen ****/
- #define main TEST__sopen
-
- #include <io.h>
- #include <fcntl.h>
- #include <share.h>
- #include <sys\stat.h>
- #include <stdio.h>
-
- void main() {
- int pan;
- pan = _sopen("test.dat",O_RDONLY | O_TEXT,SH_DENYWR);
- if (pan != -1)
- printf("File test.dat exists, handle=%d\n", pan);
- else
- printf("File test.dat cannot be sopened,"
- " error code=%d\n",pan);
-
- pan = _sopen("sopen.tmp",
- O_CREAT | O_BINARY | O_EXCL,SH_DENYWR,
- S_IREAD | S_IWRITE);
- if (pan == -1)
- printf("Cannot create file sopen.tmp,"
- " error code=%d\n",pan);
- else
- printf("File sopen.tmp has been created,"
- " handle=%d\n",pan);
- close(pan);
-
- pan = _sopen("sopen.tmp",
- O_CREAT | O_BINARY | O_TRUNC,SH_DENYWR,
- S_IREAD | S_IWRITE);
- if (pan == -1)
- printf("Cannot truncate file sopen.tmp,"
- " error code=%d\n",pan);
- else
- printf("File sopen.tmp has been truncated,"
- " handle=%d\n",pan);
- }
-
- /* End _sopen */
- #undef main
- /**** name=_spawnX ****/
- #define main TEST__spawnX
-
-
- /*
- Spawn a child process chosen by the user.
- */
-
- #include <errno.h>
- #include <stdio.h>
- #include <process.h>
- #include <string.h>
-
- void main() {
- char path[130];
- int retcode, i;
- char *args[10];
-
- printf("spawn may hang your system if this "
- "program was not run with -maxreal ffffh\n\n");
- printf("Enter name of program to spawn"
- " (with arguments): ");
- gets(path);
- if ( path[0] == 0 ) return;
- args[0] = strtok(path, " ");
- i = 1;
- while ((args[i] = strtok(NULL, " ")) != NULL)
- i++;
-
- printf("Spawning subprocess %s...\n", path);
- if ((retcode = _spawnvp(P_WAIT, path, args)) == 0)
- puts("The child process terminated normally.");
- else
- printf("Return code is:"
- " %d, errno is %d\n", retcode, errno);
- }
- /* End _spawn* */
- #undef main
- /**** name=_splitpath ****/
- #define main TEST__splitpath
-
- /*
- Create a full pathname in a buffer, then call _splitpath to break it
- into its components.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char path_buffer[_MAX_PATH];
- char drive[_MAX_DRIVE];
- char dir[_MAX_DIR];
- char fname[_MAX_FNAME];
- char ext[_MAX_EXT];
-
- /* Create a full pathname in path_buffer. */
- _makepath(path_buffer, "d", "\\highc\\inc\\",
- "makpath", "c");
- printf("Path created with _makepath: %s\n\n",
- path_buffer);
-
- /* Now split into parts. */
- _splitpath(path_buffer, drive, dir, fname, ext);
- printf("Path extracted with _splitpath:\n");
- printf(" drive: %s\n", drive);
- printf(" dir : %s\n", dir);
- printf(" fname: %s\n", fname);
- printf(" ext : %s\n", ext);
- }
-
- /* End _splitpath */
- #undef main
- /**** name=sprintf ****/
- #define main TEST_sprintf
-
- /*
- A similar example for fprintf shows the slight difference between the
- two functions.
- */
-
- #include <stdio.h>
-
- void main() {
- char String[200];
- char *S = String;
- char s[14] = "like this one";
- int i = 10, x = 255, n;
- double d = 3.1415927;
-
- sprintf(S, "sprintf prints strings (%s),%n",s,&n);
- S += n; /* The next call to sprintf must be */
- /* passed the address of the NUL */
- /* written by the last call. */
- sprintf(S, "\ndecimal numbers (%d),%n", i, &n);
- S += n;
- sprintf(S, " hex numbers (%04X),\n%n", x, &n);
- S += n;
- sprintf(S, "percent signs (%%), and\n%n", &n);
- S += n;
- sprintf(S, "floating-point numbers (%+.4e).", d);
- puts(String);
- }
-
- /* End sprintf */
- #undef main
- /**** name=_srotX ****/
- #define main TEST__srotX
-
- #include <stdlib.h>
- #include <stdio.h>
- void main() {
- unsigned short int k = 1, m = 0x8000;
-
- printf("Rotate left and right by"
- " one bit at a time:\n");
- do {
- printf("\t%4x\t\t%4x\n", k, m);
- k = _srotl(k, 1);
- m = _srotr(m, 1);
- } while (k != 1);
- }
- /* End _srot* */
- #undef main
- /**** name=sscanf ****/
- #define main TEST_sscanf
-
- #include <stdio.h>
-
- void main() {
- char buff[] = "Rick 23";
- char name[130];
- int age;
-
- sscanf(buff,"%s %d", name, &age);
- printf("My name is %s.\n", name);
- printf("My age is %d.\n", age);
- }
- /* End sscanf */
- #undef main
- /**** name=_stat ****/
- #define main TEST__stat
-
- /*
- Display information about a user-specified file.
- */
-
- #include <time.h>
-
- #include <sys\types.h>
- #include <sys\stat.h>
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
- #include <stdlib.h>
- void main() {
- struct _stat buf;
- char fname[25];
- printf("Please enter file name: ");
- gets(fname);
- printf("\nStats on file name: %s\n", fname);
- if (_stat(fname, &buf) != 0)
- perror("Problem getting info.");
- else {
- (buf.st_mode & S_IFDIR) ? puts("directory")
- : puts("not a directory");
- (buf.st_mode & S_IFREG) ? puts("ordinary file")
- : puts("not an ordinary file");
- (buf.st_mode & S_IWRITE)? puts("read/write file")
- : puts("read-only file");
- (buf.st_mode & S_IEXEC) ? puts("executable file")
- : puts("not an executable file");
- printf("File size : %ld\n", buf.st_size);
- printf("Drive number : %d\n", buf.st_dev);
- printf("Time modified: %s", ctime(&buf.st_atime));
- }
- }
-
- /* End _stat */
- #undef main
- /**** name=strcat ****/
- #define main TEST_strcat
-
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char base[30] = "This is now ";
- char tag[] = "a whole string!";
-
- puts(base);
- puts(tag);
- strcat(base, tag);
- puts(base);
- }
- /* End strcat */
- #undef main
- /**** name=_strcats ****/
- #define main TEST__strcats
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char s1[65] = "This ";
- char s2[] = "string ";
- char s3[] = "contains ";
- char s4[] = "fifty ";
- char s5[] = "characters ";
- char s6[] = "more ";
- char s7[] = "or ";
- char s8[] = "less";
- char s9[] = ".\n";
- char s10[] = "More in fact than can be printed.";
- _strcats(65, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, NULL);
- puts(s1);
- }
-
- /* End _strcats */
- #undef main
- /**** name=strchr ****/
- #define main TEST_strchr
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char *s1 = "Testing strchr.";
- char *s2 = "This is correctly tested.";
- char *s;
-
- s = strchr(s1, (int)'t');
- puts(s);
- s = strchr(s2, (int)'c');
- puts(s);
- }
-
- /* End strchr */
- #undef main
- /**** name=_strXcmpX ****/
- #define main TEST__strXcmpX
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] = "tHIS iS a tEST Z";
- char b[] = "This Is A Test z";
- char c[] = "[]";
- char d[] = "{}";
- char e[] = "1234";
- char f[] = "5678";
-
- if (_strcmpi(a,b) == 0)
- puts("_strcmpi equal test ok.");
- else puts("_strcmpi equal test failed.");
-
- if (_strcmpi(c,d) == 0)
- puts("_strcmpi unequal test failed.");
- else puts("_strcmpi unequal test ok.");
-
- if (_strcmpi(e,e) == 0)
- puts("_strcmpi equal2 test ok.");
- else puts("_strcmpi equal2 test failed.");
-
- if (_strcmpi(e,f) == 0)
- puts("_strcmpi unequal test failed.");
- else puts("_strcmpi unequal test ok.");
- }
- /* End _str*cmp* */
- #undef main
- /**** name=strcmp ****/
- #define main TEST_strcmp
-
- /*
- The program below compares two strings.
- */
-
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- void do_strcmp(char * a, char * b) {
- printf("First string: %s\nSecond String: %s\n"
- "strcmp returns: %d\n",a,b,strcmp(a,b));
- }
- void main() {
- do_strcmp("Test one!","Test one!");
- do_strcmp("Test Two.","Test two.");
- do_strcmp("Test three.","Test Three.");
- do_strcmp("a","a");
- do_strcmp("a","z");
- do_strcmp("z","a");
- }
- /* End strcmp */
- #undef main
- /**** name=strcpy ****/
- #define main TEST_strcpy
-
- #include <stdio.h>
- #include <string.h>
-
- void main () {
- char string[] = "This is what's in here now.";
-
- puts(string);
- strcpy(string, "Now it's different.");
- puts(string);
- }
- /* End strcpy */
- #undef main
- /**** name=strcspn ****/
- #define main TEST_strcspn
- /* End strcspn */
- #undef main
- /**** name=_strdate ****/
- #define main TEST__strdate
-
- #include <time.h>
- #include <stdio.h>
- void main() {
- char a[15];
-
- _strdate(&a[0]);
- puts("The date is --");
- puts(a);
- }
- /* End _strdate */
- #undef main
- /**** name=_strdup ****/
- #define main TEST__strdup
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[100];
- int j;
-
- printf("Use _strdup to malloc all of memory!\n");
- for (j = 0; j < 99; j++)
- a[j] = 1;
- a[99] = 0;
- j = 0;
- do j++;
- while (NULL != _strdup(a));
- printf("_strdup %d00 bytes before running"
- " out of heap.\n",j);
- }
- /* End _strdup */
- #undef main
- /**** name=strlen ****/
- #define main TEST_strlen
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char string[] = "Here's yet another sentence.";
- size_t i;
-
- i = strlen(string);
- printf("There are %d characters in:\n\n", i);
- printf("%s\n", string);
- }
- /* End strlen */
- #undef main
- /**** name=_strlwr ****/
- #define main TEST__strlwr
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[97];
- char *c;
- int j;
-
- for (j = 0; j < 64; j++)
- a[j] = j + 33;
- a[64] = '\n';
- for (j = 65; j < 95; j++)
- a[j] = j + 32;
- a[96] = 0;
- printf("The original string:\n\n%s\n\n",a);
- c = _strlwr(a);
- printf(" The _strlwr string:\n\n%s\n\n",a);
- printf(" The result string:\n\n%s\n",c);
- }
-
- /* End _strlwr */
- #undef main
- /**** name=strncat ****/
- #define main TEST_strncat
-
- #include <stdio.h>
- #include <string.h>
- void main() {
- char a[50] = "Testing for ";
- char b[30] = "strncat successfully failed";
- char c[10] = ".";
- char buf[50] = "Testing for strncat successful";
-
- if (strcmp(buf, strncat(a, b, (size_t)18)) == 0)
- puts(a);
- else puts(strncat(a, b, (size_t)30));
- strncat(a, c, (size_t)30);
- puts (a);
- strncat(buf, a, 50 - strlen(buf));
- puts(buf);
- }
-
- /* End strncat */
- #undef main
- /**** name=_strncat ****/
- #define main TEST__strncat
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char string1[50] =
- "This string contains forty characters. ";
- char string2[50] =
- "Plus ten. This sentence will be ignored.";
- _strncat(string1, string2, 50);
- puts(string1);
- }
-
- /* End _strncat */
- #undef main
- /**** name=strncmp ****/
- #define main TEST_strncmp
-
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char str1[] = "String one.";
- char str2[] = "String two.";
- int n = 2;
-
- printf("First string is: %s\n"
- "Second string is: %s\n",str1,str2);
- while(!strncmp(str1, str2, n)) {
- printf("The first %d characters are"
- " the same.\n", n);
- n++;
- }
- printf("The first %d characters are"
- " NOT the same.\n", n);
- }
- /* End strncmp */
- #undef main
- /**** name=strncpy ****/
- #define main TEST_strncpy
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char string1[] =
- "Original string.";
- char string2[] =
- "Modified will replace original.";
-
- puts(string1);
- puts(string2);
- strncpy(string1, string2, 8);
- puts(string1);
- puts(string2);
- }
- /* End strncpy */
- #undef main
- /**** name=_strnicmp ****/
- #define main TEST__strnicmp
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] = "tHIS iS a tEST.";
- char b[] = "This Is ANothER Test.";
- size_t i = 1;
-
- printf(" First string is: %s\n", a);
- printf(" Second string is: %s\n", b);
- printf("Equal characters are: ");
- while(_strnicmp(a, b, i) == 0)
- printf("=", i++);
- printf("^\nStrings are not equal at position %d", i);
- }
-
- /* End _strnicmp */
- #undef main
- /**** name=_strnset ****/
- #define main TEST__strnset
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] = "**failed** _strnset is working";
-
- puts(a);
- _strnset(a, '+', 10);
- puts(a);
- _strnset(a, '-', 55);
- puts(a);
- _strnset(a, '&', 11);
- puts(a);
- }
- /* End _strnset */
- #undef main
- /**** name=strpbrk ****/
- #define main TEST_strpbrk
-
- /*
- This example illustrates the use of strpbrk.
- */
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- /* tags contains letters that we want to look for in a string. str is
- the string we're looking in. ptr will hold the pointer to the first
- occurence in str of a character in tags. */
- char tags[] = "N:";
- char str[] = "Record # 7 Name: Bob.";
- char *ptr;
-
- ptr = strpbrk(str, tags);
- puts(ptr);
- }
- /* End strpbrk */
- #undef main
- /**** name=strrchr ****/
- #define main TEST_strrchr
-
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char *s = "This is a test for strrchr.";
- char *p = " ";
- int c = ' ';
-
- p = strrchr(s, c);
- puts(p);
- c = 's';
- p = strrchr(s, c);
- puts(p);
-
- c = 'i';
- p = strrchr(s, c);
- puts(p);
- c = 'r';
- p = strrchr(s, c);
- puts(p);
- }
-
- /* End strrchr */
- #undef main
- /**** name=_strrev ****/
- #define main TEST__strrev
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] = "abcdefghijklmnopqrstuvwxyz";
- char b[] = "123456789";
-
- puts("_strrev - string reversal");
- puts(a); puts(_strrev(a));
- puts(b); puts(_strrev(b));
- }
-
- /* End _strrev */
- #undef main
- /**** name=_strset ****/
- #define main TEST__strset
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[] = "_strset is working";
- char *b;
-
- puts(a);
- b = _strset(a, '-');
- puts(b);
- b = _strset(a, '+');
- puts(a);
- }
-
- /* End _strset */
- #undef main
- /**** name=strstr ****/
- #define main TEST_strstr
-
- #include <stdio.h>
- #include <string.h>
-
- void main() {
- char str[] = "When the going gets tough...";
- char mark[] = "going";
- char *ptr;
-
- ptr = strstr(str, mark);
- puts(ptr);
- }
- /* End strstr */
- #undef main
- /**** name=_strtime ****/
- #define main TEST__strtime
-
- #include <time.h>
- #include <stdio.h>
-
- void main() {
- char a[15];
-
- _strtime(&a[0]);
- puts("The time is --");
- puts(a);
- }
-
- /* End _strtime */
- #undef main
- /**** name=strtod ****/
- #define main TEST_strtod
-
- /*
- The program below computes the areas of a series of circles, given their
- diameters. A similar example for atof shows how the two functions
- differ.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #define INPUTS (5)
-
- void main() {
- char diameters[] = "1.03 67.94 9.2032e27 4 8e-32";
- char *diameter = diameters;
- double pi = 3.141593;
- double diam;
- double area[INPUTS];
- int i = 0;
-
- /* While not at end of string. */
- while (*diameter) {
- diam = strtod(diameter, &diameter);
- area[i] = pi * diam * diam / 4.0;
- printf("\ndiam=%-20.5g \tarea=%g",
- diam, area[i++]);
- }
- }
-
- /* End strtod */
- #undef main
- #undef INPUTS
- /**** name=strtok ****/
- #define main TEST_strtok
-
- #include <stdio.h>
- #include <string.h>
- void main () {
- char sentence[] = "Here's a sentence; it's complete,\
- whole. Parse this!\n";
- char limits[] = " .,?;:\"!";
- char *tmp;
- if((tmp = strtok(sentence, limits)) == NULL)
- return;
- do {
- printf("%s ", tmp);
- } while((tmp = strtok(NULL, limits)) != NULL);
- }
- /* End strtok */
- #undef main
- /**** name=strtol ****/
- #define main TEST_strtol
-
- /*
- The program below computes the number of seconds in one week, one day,
- one hour, one minute, and one second.
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #define WEEK "604800"
- #define DAY "86400"
- #define HOUR "07020" /* Octal */
- #define MINUTE "0x3c" /* Hexadecimal */
- #define SECOND "1"
-
- void main() {
- char *list[] = {WEEK, DAY, HOUR, MINUTE, SECOND, 0};
- char *stopstring;
- unsigned long seconds = 0;
- int i = 0;
-
- while (list[i] && *list[i]) {
- seconds += strtol(list[i], &stopstring, 0);
- i++;
- }
- printf("Total number of seconds in a week, day, hour"
- ", minute,\nand second = %ld.\n", seconds);
- }
- /* End strtol */
- #undef main
- #undef WEEK
- #undef DAY
- #undef HOUR
- #undef MINUTE
- #undef SECOND
- /**** name=_strupr ****/
- #define main TEST__strupr
-
- #include <string.h>
- #include <stdio.h>
-
- void main() {
- char a[97];
- char *c;
- int j;
-
- for (j = 0; j < 64; j++)
- a[j] = j + 33;
- a[64] = '\n';
- for (j = 65;j < 95; j++)
- a[j] = j + 32;
- a[96] = 0;
- printf("The original string:\n\n%s\n\n",a);
- c = _strupr(a);
- printf(" The _strupr string:\n\n%s\n\n",a);
- printf(" The result string:\n\n%s\n",c);
- }
-
- /* End _strupr */
- #undef main
- /**** name=_swab ****/
- #define main TEST__swab
-
- #include <stdio.h>
- #include <stdlib.h>
-
- void main() {
- char a[] = "abcdefghijkl";
- char b[13];
-
- b[12] = 0;
- _swab(a, b, 12);
- puts("_swab - swap bytes");
- puts(a);
- puts(b);
- }
-
- /* End _swab */
- #undef main
- /**** name=system ****/
- #define main TEST_system
-
- #include <stdlib.h>
-
- void main() {
- char c[129];
-
- printf("system may hang your machine if"
- " this program was not run with"
- " -maxreal ffffh\n\n");
- printf("Enter command line for system: ");
- gets(c);
-
- if (c[0]) system(c);
- }
- /* End system */
- #undef main
-
- /*****names*****/
-
- char * names[]={
- "scanf",
- "_searchenv",
- "_segread",
- "_setmode",
- "_setrpvectp",
- "setvbuf",
- "signal",
- "sin",
- "sinh",
- "_skip_char",
- "_sopen",
- "_spawnX",
- "_splitpath",
- "sprintf",
- "_srotX",
- "sscanf",
- "_stat",
- "strcat",
- "_strcats",
- "strchr",
- "_strXcmpX",
- "strcmp",
- "strcpy",
- "_strdate",
- "_strdup",
- "strlen",
- "_strlwr",
- "strncat",
- "_strncat",
- "strncmp",
- "strncpy",
- "_strnicmp",
- "_strnset",
- "strpbrk",
- "strrchr",
- "_strrev",
- "_strset",
- "strstr",
- "_strtime",
- "strtod",
- "strtok",
- "strtol",
- "_strupr",
- "_swab",
- "system",
- "",""};
- int nextfunum;
- void main() {
- char ans[90];
- for (;;) {
- for (int j=0;j< 45;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_scanf();break;
- case 2:TEST__searchenv();break;
- case 3:TEST__segread();break;
- case 4:TEST__setmode();break;
- case 5:TEST__setrpvectp();break;
- case 6:TEST_setvbuf();break;
- case 7:TEST_signal();break;
- case 8:TEST_sin();break;
- case 9:TEST_sinh();break;
- case 10:TEST__skip_char();break;
- case 11:TEST__sopen();break;
- case 12:TEST__spawnX();break;
- case 13:TEST__splitpath();break;
- case 14:TEST_sprintf();break;
- case 15:TEST__srotX();break;
- case 16:TEST_sscanf();break;
- case 17:TEST__stat();break;
- case 18:TEST_strcat();break;
- case 19:TEST__strcats();break;
- case 20:TEST_strchr();break;
- case 21:TEST__strXcmpX();break;
- case 22:TEST_strcmp();break;
- case 23:TEST_strcpy();break;
- case 24:TEST__strdate();break;
- case 25:TEST__strdup();break;
- case 26:TEST_strlen();break;
- case 27:TEST__strlwr();break;
- case 28:TEST_strncat();break;
- case 29:TEST__strncat();break;
- case 30:TEST_strncmp();break;
- case 31:TEST_strncpy();break;
- case 32:TEST__strnicmp();break;
- case 33:TEST__strnset();break;
- case 34:TEST_strpbrk();break;
- case 35:TEST_strrchr();break;
- case 36:TEST__strrev();break;
- case 37:TEST__strset();break;
- case 38:TEST_strstr();break;
- case 39:TEST__strtime();break;
- case 40:TEST_strtod();break;
- case 41:TEST_strtok();break;
- case 42:TEST_strtol();break;
- case 43:TEST__strupr();break;
- case 44:TEST__swab();break;
- case 45:TEST_system();break;
- default:printf("I don't recognize that answer\n");nextfunum=-1;break;
- }
- printf("\n\npress enter to select another function\n");
- gets(ans);
- }
- }
-