EasyManuals Logo

HP NonStop SQL/MP User Manual

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #252 background imageLoading...
Page #252 background image
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-54
Detailed Dynamic SQL Program
603 /* ********************************************************** */
604 /* FUNCTION get_string */
605 /* This function reads from the standard input, a character */
606 /* string, into the data_array */
607 /* Tha data_array will be null terminated, or blank padded, */
608 /* as requested. The reading stops when 'terminator' char is */
609 /* read or if array_size number of characters have been read, */
610 /* whichever comes first */
611 /* */
612 /* For multi-line input, all white space characters are */
613 /* replaced by blanks */
614 /* */
615 /* Return: +ve integer, if successful; = the number of chars */
616 /* read from the input (minus the terminator char) */
617 /* -1 if entered data is too long for data_array */
618 /* (if no room for the null terminator (if reqsted) */
619 /* (if array_size not enough for entire input, ie */
620 /* until the semicolon ) */
621 /* ********************************************************** */
622
623 short get_string( char *data_array, /* array to read data into */
624 short array_size, /* max #bytes in array */
625 short nullit, /* if != 0, terminate */
626 /* data_array on return, */
627 /* else blank pad array */
628 char terminator ) /* terminator character */
629
630 { /* begin get_string */
631
632 char c;
633 short ix; /* next available slot */
634 /* also return code */
635 short i; /* loop index */
636
637 /* sanity check */
638 if (array_size == 0) /* buffer no good */
639 return (-1);
640
641 ix = 0;
642 while ( (c = getchar()) != terminator )
643 {
644 if ( c == '\t' || c == '\n' )
645 *(data_array + ix) = ' '; /* replace by blank */
646 else
647 *(data_array + ix) = c;
648
649 if (++ix >= array_size) /* no more room in array */
650 { if (nullit == 0) /* blankpadding requested */
651 { if ( (c = getchar()) == terminator )
652 { /* the next char was the terminator anyway. */
653 /* just made it. also consume extra input */
654 /* at while-loop exit */
655 break;
656 }
657 else
658 { while ( (c = getchar()) != '\n' )
659 { /* consume the input */ }
660 return (-1); /* array too small */
661 }
662 }
663 else /* null termination rqsted */
Example 10-8. Detailed Dynamic SQL Program (page 11 of 22)

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the HP NonStop SQL/MP and is the answer not in the manual?

HP NonStop SQL/MP Specifications

General IconGeneral
BrandHP
ModelNonStop SQL/MP
CategorySoftware
LanguageEnglish

Related product manuals