CCL Home Page
Up Directory CCL test
main()
   {
   char line[100];
   char field[5];

   strcpy(line,"01234567890123456789");
   printf("%s\n",pfield(line,3,"hello"));
   printf("%s\n",pfield(line,0,"start"));
   printf("%s\n",pfield(line,18,"endofit"));
   printf("%s\n",pfield(line,-18,"waybefore"));
   printf("%s\n",pfield(line,38,"wayafter"));


   }

char *pfield(line,field_start,field)
/*============================================================================*/
/* PURPOSE: PUT A FIELD INTO A LINE.  A FIELD IS ANY CONTIGUOUS SPAN OF
/*	CHARACTERS STARTING AT AN ARBITRARY POINT.  THE SUPPLIED FIELD IS
/*	OVERLAYED ONTO THE SUPPLIED LINE, OVERWRITING PREVIOUS CHARACTERS THAT
/*	OCCUPY FIELD POSITIONS.  THE TRAILING NULL OF THE FIELD IS *NOT*
/*	TRANSFERRED TO THE LINE.  NO CHECK IS MADE TO DETERMINE IF THE FIELD
/*	IS INSIDE OR OUTSIDE THE SUPPLIED LINE (IT IS ASSUMED THAT THE ENTIRE
/*	FIELD LIES *INSIDE* THE LINE).  THE NEW LINE IS RETURNED.
/* WRITTEN: M.V.GRIESHABER
/* LAST MODIFICATION: 22 JUNE 1993 MVG
*/
   char line[];		/* ORIGINAL LINE. */
   int field_start;	/* STARTING CHARACTER POSITION OF FIELD. */
   char field[];	/* FIELD TO BE INSERTED, NULL TERMINATED. */
   {
   char *line_pos;	/* CHARACTER POSITION IN LINE. */
   char *field_pos;	/* CHARACTER POSITION IN FIELD. */
   int line_length;	/* ORIGINAL LENGTH OF LINE. */

   if (field_start>=0)
      {
      line_pos= &line[field_start];
      line_length=strlen(line);

      for (field_pos=field; *field_pos!='\0' && (line_pos-line+1)<=line_length; field_pos++)
         {
         *line_pos++ = *field_pos;
         }
      }

   return(line);
   }
Modified: Fri Feb 11 17:00:00 1994 GMT
Page accessed 4850 times since Sat Apr 17 21:59:01 1999 GMT