|
|
1.1 ! root 1: /* Copyright Bell Telephone Laboratories Whippany, N.J. ! 2: ! 3: * ///////////////////////////////////// ! 4: * ///////////////////////////////////// ! 5: * ////////////// right.c /////////////// ! 6: * /// J. P. Hawkins WH X4610 8C-001 /// ! 7: * ///// Thu Mar 5 06:15:32 1981 ////// ! 8: * ///////////////////////////////////// ! 9: * ///////////////////////////////////// ! 10: * @(#) right.c: V1.1 3/5/81 ! 11: ! 12: * function right$(string,n) ! 13: * where the last n chars of the string are returned ! 14: * n is a number or numerical expression ! 15: */ ! 16: ! 17: extern char scratch[]; ! 18: ! 19: char * ! 20: right(args) ! 21: char args[]; ! 22: { ! 23: double evalx(); ! 24: char *prncpy(); ! 25: char *holdptr; ! 26: char num[20]; ! 27: int number,length; ! 28: char result[80]; ! 29: ! 30: holdptr = args; ! 31: holdptr = prncpy(result,args)+1; /* point to string field */ ! 32: prncpy(num,holdptr); /* get number of chars */ ! 33: evals(result,scratch); ! 34: number=(int)evalx(num); /* convert expr to integer */ ! 35: length=strlen(scratch); /* get actual length of string */ ! 36: if(number > length) /* if requested number > length */ ! 37: number = length; /* just return the string */ ! 38: strncpy(result,&scratch[length-number],number); ! 39: result[number] = '\0'; ! 40: return(result); ! 41: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.