Guys need some advice. I am working on a algorithm for multiple string searching using OpenMp.

So within my program I am trying to initialise each elements of an array to a value of a variable.

What I mean by is say if I have array intialised as shown below:

lastI = textLength - patternLength

int* Loc;
Loc = malloc(sizeof(int) * control);

My Questions:

1. Now, I want to further initialise each elements within the array to a variable called
'textLength' as shown above which I am not sure on how to? :$

2. Also I have a variable called 'max' which I intend on using it for comparison in the latter part of the code. But I want to know as how I can set this max variable to the first element of the said array?

Thanks

Recommended Answers

All 9 Replies

Do you know how to do it if you defined the array as int Loc[100] ?
It's the same...

Do you know how to do it if you defined the array as int Loc[100] ?
It's the same...

Something like this?

Loc[1] = textLength;	
	Loc[2]= textLength;
	Loc[3]= textLength;
	Loc[4]= textLength;
	Loc[5]= textLength;
	Loc[6]= textLength;
	Loc[7]= textLength;
	Loc[8]= textLength;
	Loc[9]= textLength;
       Loc[10]= textLength;

:$

Something like this?

Loc[1] = textLength;	
	Loc[2]= textLength;
	Loc[3]= textLength;
	Loc[4]= textLength;
	Loc[5]= textLength;
	Loc[6]= textLength;
	Loc[7]= textLength;
	Loc[8]= textLength;
	Loc[9]= textLength;
       Loc[10]= textLength;

:$

Yeah, kinda like that.

You will get a lot better help by joining their OpenMP forums.

Yeah, kinda like that.

Thanks, but i am getting segmentation fault :(

The length of the array is equal to 'control'.
So, I think if control < 10 then it might be accessing outside the array hence causing the fault.

Perhaps initialisng the array in a for loop determined by the value of 'control', how could I do this?

Thanks

My psychic powers aren't working well, your code is coming in cloudy... All I can sense is there's something wrong with it.

My psychic powers aren't working well, your code is coming in cloudy... All I can sense is there's something wrong with it.

:D

I was able to solve the issue by using the mentioned for loop and seemed to work the magic.

Although I have another problem. I want to sort the values printed out by my arrays, but not exactly sure on how to do it. I have come across qsort and bubble sort but not sure on how to implemented it into my code.

Please advice.

Here is my algorithm: In the code Loc is my array.


for(i=0; i<control;i++)
	{
		if( Loc[i] == textLength )
		{
			if( i==0 )
			{
				printf("-1\n");
			}
			break;
		}
		else
		{
			printf("%d\n", Loc[i]);
		}
	}

I used bubble sort technique and worked fine. Now from what I have heard bubblesort are not efficient for large sets of data, is it true?

Now from what I have heard bubblesort are not efficient for large sets of data, is it true?

For the most part, yes. For the quadratic sorts, insertion sort is a better choice, though qsort from <stdlib.h> should be the first algorithm you turn to since it's highly likely to be some variant of quicksort.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.