Page 1 of 1

A simple parallel routine

Posted: Fri Sep 17, 2004 4:14 am
by richdhan
Hi All,

I need to create a simple parallel routine which returns a substring. The C program to get the substring is as follows

Code: Select all

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>

char *substr(char*,int,int);
main(int argc,char *argv[])
{
	char *z;
	z = substr(argv[1],atoi(argv[2]),atoi(argv[3]));
	printf("%s\n",z);
	free(z);
}
char *substr(char *str,int st,int len)
{
	int i,j=0,l;
	char *s;
	l = strlen(str);
	if(len > 0)
		s = (char *)malloc(100);
	else
		return("");
	if(l < abs(st))
		return("");
	if(st == 0)
		st = 1;
	if(st < 0)
		st = st + l + 1;
	for(i=st-1; i<st+len-1; i++)
	{
		s[j] = str[i];
		j++;			
	}
	s[j] = '\0';
	return(s);
}
I have the object file for this C program.

My concern is that the main program can return only integer. How to return string. How do I create a parallel routine that returns a string provided with the input string, the starting position and the length as inputs for the C object file.

Thanks in advance
--Rich

Pride comes before a fall
Humility comes before honour

Posted: Fri Sep 17, 2004 9:33 am
by Eric
A PX routine is a library/object file used by DataStage not an external program. These don't use 'main', you call the function directly.