Thinka 40 Posting Whiz Team Colleague

Hi everyone,

Just wondering if anyone can point me in the direction of software that can play RENTAL DVDs because the ones I have (RealPlayer and VLC Media Player) aren't doing it. They playe non-rental (bought) DVDs fine though.

And whilst I'm at it, my WMP doesn't play any DVDs full stop, I believe it's a codec issue, can I get one for free cos the ones I've seen on the MSFT website aren't?

Cheers

Thinka 40 Posting Whiz Team Colleague

Oh I see, ok then thanks.

Thinka 40 Posting Whiz Team Colleague

The title of the thread is my random yet hopefully simple question. I "googled" it but didn't find anything that seemed concrete, and so I'm hoping that someone on here will know. So again the question is, Is Vista based on XML, and if so, would it be correct to say that the document formats are based on XML?

In case anyone is thinking so I promise this is not some assignment or such, I'm just trying to cross-check what someone told me.

Thinka 40 Posting Whiz Team Colleague


Next problem:
You have a functiondefenition that expects an array of ints ([B]int[/B] binarySearch[B](int[/B] sortedArray[B][][/B], [B]int[/B] first, [B]int[/B] last, [B]int[/B] key[B])[/B]; . But you are calling it with only one element of an array, so one int in other words.

And there are a few more things wrong, but first correct these :icon_smile:

Regards Niek

Hey niek, thanks for the code critique. I have included a new variable to contain the value returned by the binarySearch function. However I'm not sure what you mean by I'm only calling the binarySearch function with one element of an array/one int? Would you please expand on that a little? Many thanks

Thinka 40 Posting Whiz Team Colleague

Thanks sos. Now the program finds all the numbers in the array... the only problem is that it also finds numbers that aren't in there, and even letters. Which suggests that the binarySearch function is always ending in the 'else' part that says "pos = mid"... Any ideas how I can fix this please?

Thinka 40 Posting Whiz Team Colleague

Right, so I have written a few new functions, including one for the binary search as suggested. Annoyingly, it is this same function that I can't get to work... At the point where I call it in int main() I get a Segmentation Fault. I think it might be something small, but I can't for the life of me pick out what that is. Anybody who can care to shed some light on it for me please?

#include<stdio.h>
#include<stdlib.h>

void insertArray(int n);
void sortArray(int n);
int binarySearch(int sortedArray[], int first, int last, int key);
 
int a[];

void insertArray(int n)
{
	int i;
	for (i = 0; i < n; i++)
		a[i]=i+1;
}

void sortArray(int n)	/* Using selection sort */
{
	int i, j, min, temp;
	
	for(i = 0; i < n-1; i++)
	{
		min = i;
		for(j = i+1; j < n; j++)
		{
			if (a[j] < a[min]) 
			{
				min = j;
				/* Swap the minimum value for first value*/
				temp = a[i];
				a[i] = a[min];
				a[min] = temp;
			}
		}
	}
}

int binarySearch(int sortedArray[], int first, int last, int key)
{
	int pos = -1;
	while (first <= last)
	{
		int mid = (first + last) / 2;
		if (key > sortedArray[mid])
			first = mid + 1;
		else if (key < sortedArray[mid])
			last = mid - 1;
		else
		{
			pos = mid;
			break; // Number has been found, exit loop
		}
      }
      return pos;
}

int main(void)
{
	int n = 5;
	int i, j, temp; …
Thinka 40 Posting Whiz Team Colleague

And on looking at the code again, I realise that all I might be needing is an if statement that says if the number entered is equal to the mid (i.e. the 3rd item in the array), then to just print that out. Is that all I need to do? Because I tried it and that made the program worse, it started printing out the 'number found' lines infinitely.

Thinka 40 Posting Whiz Team Colleague

Instead of using pointer variables for marking the beginning and the end, make your life simpler by keeping numbers as markers. That the calculations would become simpler and more logical. The bugs cropping up in your program are because of pointer calculation.

How about something simple like this?

Hi sos, thanks for the tip + link, I have incorporated both things into my program, and it seems to work, except that when I search for the 3rd item in the array, the program just terminates - it doesn't say either it found the number or it didn't even though I've got printf statements to handle both eventualities. I tried this for an array of 5 and 6 elements, and got the same thing.

The relevant section of the code is

// Assign variables to the beginning and end of the array

	b = 0;
	e = n-1;
	
	printf("This is the value of b: %d\n", b);
	printf("This is the value of e: %d\n", e);
	
	printf("\n Enter the number to be searched:");
	scanf("%d", &u);

	// This is the binary search
		
	while (b <= e)
	{
		m = (b + e) / 2;	/* Mid-point calculation*/
	
		if (u > a[m])
			b = m + 1;
		else if (u < a[m])
			e = m - 1;
		else
			return m;
			printf("Number %d has been found!\n", u);
	}
		
	return -(b + 1);
	printf("Sorry the number was not found. Goodbye!\n");

	return 0;

The rest of the code is pretty much as before. Hope …

Thinka 40 Posting Whiz Team Colleague

OK, I've indented the code, and put print statements in the Binary Search algorithm part of the code. The algorithm seems to recognise when a number is higher than or lower than the middle point, but it still doesn't find some numbers. I have been testing it with an array of 5 integers, and it only finds the middle and the last number in the array. So in an array containing 1,2, 3, 4, 5 if I search for all the numbers one after the other, the program finds only 3 and 5. Can anyone help out here please, I've checked the code with text books, and it appears to be right.

#include <stdio.h>
int a[5];

int main(void)
{
	int n, i, j, temp;
	int *beg, *end, *mid, target;
	int b, e, m;
	n = 5;
	
	printf("Please enter 5 integer array elements:\n" );

	for(i = 0; i < 5; i++)
	{
		scanf("%d", &a[i]);
	}


	/*The sorting is done here*/
	for(i = 0; i < n-1; i++)
	{
		for(j = 0; j < n-i-1; j++)
		{
			if (a[j+1] < a[j])
			{
				temp = a[j];
				a[j] = a[j+1];
				a[j+1] = temp;
			}
		}
	}

	printf("The sorted numbers are:");

	for(i = 0; i < n; i++)
	{
		printf("%d ", a[i]);
	}
	printf("\n");
	
	// Point to 'beginning' and 'end' of the array

	beg = &a[0];
	end = &a[n-1]; // use n = one element past the loaded array!

	printf("\nVariable 'beg' points to address %d and 'end' points to %d", beg, end); // test …
Thinka 40 Posting Whiz Team Colleague

Hello once again people; I hope I'm not breaking any rules or being cheeky. But I was searching for algorithms/programs on the internet that would help me with my binary search program, and then I came across the piece of code posted here (in the code snippets section)about just the type of searching I want to do - within an integer array. The page containing this code can be found here http://www.daniweb.com/code/snippet164.html.
So I ran this code, and it seemed to work alright... until I put in multiples of 5 and asked it to search for one of the numbers I put in. With this type of data (integers with steps of 5 between them), for some reason, it doesn't find some numbers. It's very erratic behaviour. Can anyone please tell me if I've done something wrong, or if the code is sort of meant to be like that?

I've included it below for anyone who's interested

// binary search of an integer array, this search is efficient for large arrays
// tested with PellesC vegaseat 24jan2005


#include <stdio.h>



int main(void)
{

int a[20] = {0};

int n, i, j, temp;

int *beg, *end, *mid, target;


printf(" enter the total integers you want to enter (make it less then 20):\n");

scanf("%d", &n);

if (n >= 20) return 0; // Ouch, too many!

printf(" enter the integer array elements:\n" );

for(i = 0; i < n; i++)

{

scanf("%d", &a[i]);

}


// sort the loaded array, …
Thinka 40 Posting Whiz Team Colleague

Thanks very much people, I am now timing my programs using clock(). Seems to give fairly decent graphs, although I think I need to run the programs more often to get a better average.

Still, all input has been very much appreciated.

Thinka 40 Posting Whiz Team Colleague

never heard of it until yesterday. Its a linux/unix-specific function and most posters here use MS-Windows os.

Ah right, interesting. Well I use MS-Windows too, but I have to run my C programs through the compilers on the Unix servers at my universities. Which I guess means I'm sort of working on unix doesn't it?

Thinka 40 Posting Whiz Team Colleague
clock_t start, end;
double cpu_time_used;
start = clock();   
/* whatever */
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;

I've added an adaptation of this into my program. I print out cpu_time_used in floating point format. Is this value in seconds, because I have divided by CLOCKS_PER_SEC?

Thinka 40 Posting Whiz Team Colleague

Thanks everyone for all your posts. Will try different solutions and see what works. Thing is, does the fact that noone has mentioned getrusage() mean that noone here uses it?

Thinka 40 Posting Whiz Team Colleague

Hello again people, I've got some questions about timing that I hope can be answered by someone.
I'm trying to use the functions getrusage or times, or the time command to time my programs. Now I've got this piece of code that uses getrusage, and my first question is a bit of a daft one, can anyone please tell me what unit t is given in? I got 1086556160 last time I ran the program. Is this milllionths of a second or what?

#include<stdio.h>
#include<stdlib.h>
#include<sys/time.h>
#include<sys/resource.h>

double getcputime();

int main(void)
{
int i, n, a;
double t;

n = 13;
printf("The 5-times Table\n");
for(i=1;i<n;i++)
{
	a = (i * 7);
	printf("%d\t%d\n", i, a);
}

printf("\n");
t = getcputime();
printf("The total time taken by the system is: %d (in decimal format)\n", t);

return 0;
}

double getcputime(void)
{
	double t;
	       struct timeval tim;        
               struct rusage ru;
	       getrusage(RUSAGE_SELF, &ru);
               tim=ru.ru_stime;
               t=(double)tim.tv_sec * 1000000.0 + (double)tim.tv_usec;        
               return t;
}

My second question is more general (for now), does anyone know why very few textbooks talk about timing programs, and even if you wanted to use the system clock, surely that is only accurate to seconds, and therefore not what is needed to time a relatively fast program?

Thinka 40 Posting Whiz Team Colleague

See this thread

Hehe, I get it.:P. Was just being a bit too curious.

Thinka 40 Posting Whiz Team Colleague

Hi there, I just wanted to say, I think you all are making very valid points, and I think it's just unfortunate that some people don't use decent grammar in forums and seem to ask people to do their work for them - I mean even in a school setting, you'll be hard pushed to find a classmate or member of staff who will just do your work for you. Still though I just like to hope that all people who ask for help (including me) aren't tarred with the same brush, but are looked upon individually because I have seen some people put some effort when they've posted questions.

And as a small aside, does Daniweb by any chance use a css file that means that visited links don't change colour? Just something I noticed...:-p

Thinka 40 Posting Whiz Team Colleague

Yes, that IS a useful thread, thanks again!

Thinka 40 Posting Whiz Team Colleague

Again, apologies, so embarassing, I solved the 2nd qstn, I have to use the same value in lines 11 & 13 if I'm going to use something different from 'available'.

Thanks v much for all your help vijayan, it's very much appreciated!

Thinka 40 Posting Whiz Team Colleague

Yea you're right, now it works. Thanks so much, you've been amazing. But may I please ask a couple more things: "--required" decrements that variable so that the number entered into the function is the number of numbers printed out right?
And how can I adjust the range pls?I tried putting a variable with a smaller number in the place of 'available' in line 13 & it compiled, but when i ran the program I got an 'Arithmetic Exception'. Sorry to keep hassling like this.

Thinka 40 Posting Whiz Team Colleague

Hmmm. I've put 1024 in there, and it sure prints out a lot of numbers, which might well be 1024 numbers. But when I put in 10, it prints out 98 numbers, and when I put in 5, it prints out 50 numbers. I've tried this more than once now... any ideas why this is happening please?

Thinka 40 Posting Whiz Team Colleague

OK, I'm being silly, this is the correct version of the code that compiles and runs.

#include <stdio.h>
#include <stdlib.h>

int i;

void generate_ascending_number(int n)
{
int available = RAND_MAX;
int required = n;

for (i=0; i<available; ++i) 
{
	if ( (rand() % (available-i)) < required)
		{
			printf("%d\t", i);
		}

}

}

int main()
{
generate_ascending_number(20);
return 0;
}

Thanks very much vijayan! Now when it runs I get 176 numbers printed out in sequence... How can I get more control over how many it prints out, because I'll be wanting to do up to 10,000, and possibly more? Is it by playing around with line 12?

Thinka 40 Posting Whiz Team Colleague

Hey vijayan is that C++, because I'm using C..?

I guess I can try to convert most of it though, afterall it's only an algorithm, shouldn't be too hard right??

After typing out code...
Err, sorry, but what is meant to be happening in lines 15 & 16 of the code you put vijayan? I've got this so far

#include <stdio.h>
#include <stdlib.h>

void generate_ascending_number(int n)
{
int available = RAND_MAX;
int required = n;

for (int i=0; i<available; ++i)
if ( (rand() % (available-i)) < required)
{

}
}

int main()
{
generate_ascending_number(50);
return 0;
}
Thinka 40 Posting Whiz Team Colleague

What happens if the current number is larger that the previous one, but
smaller than the one before the previous one? How would you know that?

Hey Aia, I guess I am assuming that if I start from zero, then I can keep generating random numbers, telling the program which ones I want to keep & print to file i.e. the one that is larger than the previous one written to file; and then just keep looping that?:-/

Thinka 40 Posting Whiz Team Colleague

Thanks Lerner,

I DO want to have the same random sequence each time I run the program so I think for now I don't want to seed rand(). And I do know a bit about sorting, but I'm not allowed to use it for this problem.
So basically, I want to generate random numbers, but then write them to a file or the screen in an increasing sequence, which means that I want to control rand a bit... Maybe have a temporary variable or something.

Actually, my idea is to run rand (not sure how many times I'll need to), and to then say for each time it returns a number, the program should check that current number with the previous one; if the current number is larger than the previous one, it gets printed to screen, if not, it gets ignored (i.e. nothing happens to it) and rand keeps going. And I'm finding that quite challenging at the moment.

Thinka 40 Posting Whiz Team Colleague

Thanks Dragon, I did that, and I got 26 of the 50 numbers printed out on the screen, and the remaining 24 printed out to the file. The first number printed to the screen is '0', but all the numbers are random, no increasing sequence like I want.
Is there another way I can rework the control statements to print the numbers in order?

Thinka 40 Posting Whiz Team Colleague

Hey, I'm hoping someone can help out here. I'm trying to use the rand() function to generate sequential random numbers in C, and then write them to file. Now I know it's possible, I'm just not sure whether it is the way I want to do it. I have already used the rand function to generate numbers and write them to file, it's just the doing it in sequence that's being a big pain.
Now at the mo I've got this code:

#include <stdio.h>
#include <stdlib.h>

FILE *bptr; /* Pointer to file 'bptr' */
int i, j, k, n;

int main(void)
{
	printf("\nOpening file bptr.txt for reading...\n");
	
	if ((bptr = fopen("bptr.txt", "w")) == NULL)
	 {
	  printf("\nI won't open file cos there's an error\n");
	  exit(1);
	 }
	 else
	 {
	  printf("\nI've opened file cos you asked for it.\n");
	 }
	 
	 /* For loop to generate 50 random numbers*/ 
	 for (i = 0; i < 50; ++i)
	 {
	  if (i % 14 == 0)
		  putchar('\n');
	  j = rand();
	  k = j; /* Assign random number generated to a variable*/
	  
	  if (k > j) /* Attempt to check if random number generated is larger than previous, if it is then it gets printed to file, else it gets printed to screen */
	 {
		 fprintf(bptr, "\n%d\t", k);
	 }
	 else
		 printf("%7d\t", k);
	 
	 /*if (i < j)
		  fprintf(bptr, "\n%d\t", j);
	  //printf("%7d", j);*/
	  }
	  
	  /*for ( ; i < j; ++i)
	  {
		  j = k;
	  
	  }*/
	 
	 printf("\n");
	  	 
	 printf("\nClosing text file...\n");
	 
	 fclose(bptr);
		  
	 return 0;
}

All it gives me …

Thinka 40 Posting Whiz Team Colleague

Yes Sophe I am talking about media player updates... don't want to confuse you, but I tend to only update things if I think they're necessary. What is the state with WMP now, still no sound?

Thinka 40 Posting Whiz Team Colleague

Yea, WMP keeps telling me it wants to update, I just click 'No' and carry on with my life as I know it. Keeps me sane. Sophe you probably don't want WMP 11 if you can help it...

Thinka 40 Posting Whiz Team Colleague

OK jwenting, thanks, I changed the type to int, so that now my code compiles and runs with no errors, but the test doesn't work :). The joys of hacking code. Anyone know or recommend any good (current) books for absolute beginners with no teachers to help out?

Thinka 40 Posting Whiz Team Colleague

Hey aniseed, i'm using Eclipse, and it doesn't seem to like me using "equals()".

It also has a problem with my reading in line, i've got

s=stdin.read();

and it told me that it couldn't convert an integer to a character (which sounds reasonable enough!)
Any ideas as to how to make that a character reading in line?

Thinka 40 Posting Whiz Team Colleague

Hi, I am new to Java, and have been trying to write a program that calculates the square root of a number using the Babylonian/Heron method. I have been able to make it work, largely due to a lot of help from a PhD student.
So yeah, what I'm trying to do now is to create a do-while loop so that a user chooses whether they want to exit the program or not.

So far i've got

System.out.println("Press y to continue using the program or any other character to exit");
		s = stdin.read();
		System.out.println( );
		}
		while (s = "y"){

Where s is the variable name of whatever the user's response is. I want to say if the user presses y, for the whole program to run again, and if they don't, for the program to terminate.

All help is appreciated, thanks guys.

P.S. the relevant java class files are attached.

Thinka 40 Posting Whiz Team Colleague

YAAAAY IT WORKS! Phew OK, that's my first bad experience with Apple Inc. And the 2nd of its products that I'm really not a fan of. The first is the iPod :-p
Still wanna get a Mac Book Pro tho...

Anyways thanks guys, appreciate your time & help (Y)

Thinka 40 Posting Whiz Team Colleague

Hey thanks linux. I did what u guys said but I still can't watch videos on Firefox. Now I feel thick cos I'm thinking I must be doing something wrong, and I don't like feeling thick, so i want to remove QuickTime from my computer completely. That should be ok right, I mean according to MidiMagic you don't need it for Firefox do ya?

Thinka 40 Posting Whiz Team Colleague

Mmm OK that sounds really good JBennet. Except now it sounds like i'll need BOTH the TV card AND an adapter (as opposed to me just thinking I could use one or the other). Neways gonna wait till I get one or the other, then I'll let u know how it goes...
Cheers tho

Thinka 40 Posting Whiz Team Colleague

Ah right K. Yea I was thinking about a TV card, but then don't they have just the one socket against the PS2's 3 plugs (red, white and yellow)? I mean in my experience you may use just two of the three and it'll work just fine, but surely using the one would just be pushing it, no?

Thinka 40 Posting Whiz Team Colleague

Thanks for the reply Magic. I understand what you said, but I think the only issue is how do I know what I don't want QuickTime to try to open? I mean I would have thot that it only associated itself with filetypes that it can actually open?? Cos I'm seeing stuff like SDP files, of which I have no idea about what else can open it...
Also, and this is sort of related, is there a way, and if so how, can I find out the type of files that quicktime tries to open but fails to?

Hope u can help?

Thinka 40 Posting Whiz Team Colleague

I got 8/10 right in the mini test... pretty pleased with myself as I thought I'd get much less. Shan't attempt any of the other tests tho, not until I'm pretty sure I can score over 50%!! Nice site tho

Thinka 40 Posting Whiz Team Colleague

Hello all,

I've been using Firefox for over a year now I think, ages anyway, and ever since I've never really been able to view motion-media on it (i.e. videos on YouTube, adverts and banners, websites with a flash intro, etc). So if I go to YT for instance, I get a big blue 'Q' come up where the video should be. Now I know this Q stands for QuickTime, and I know that this problem should be solvable by downloading plugins, but I have done this and it doesn't seem to work. And yes I have QuickTime, iTunes, Macromedia Shockwave Player, Adobe Flash Player all on my computer but still no joy.

Sometime last year I was able to watch videos on it for a little period, I think I might have re-installed it (Firefox that is). However this stopped, possibly after I updated my QuickTime/iTunes to the next version (any suggestions as to whythis might have happened??). Since then I just haven't bothered trying to get it to work, but it still nags at me, because I know a few other Firefox users & they don't have this problem.

Now I should say, I can watch videos on IE, and that is one of the only reasons I still have it on my computer. It's kind of annoying, but I do switch to IE when Firefox won't let me view a website's content properly, and it works fine.

Any ideas? Is it just an …

Thinka 40 Posting Whiz Team Colleague

Nah it's alright Shaft. Erm anyone know about the PCI Card option? I've got two PCI slots just waiting to be filled...

Thinka 40 Posting Whiz Team Colleague

Good diagnosis J (Y) :)

Thinka 40 Posting Whiz Team Colleague

Good point, cheers J (Y)

Thinka 40 Posting Whiz Team Colleague

Hey Shaft thanks for that. However I also found this http://www.amazon.co.uk/Tuner-Multi-Input-Adapter-PAL/dp/B0009V9DYO

and now I'm slightly confused because I can't tell if they both perform the same kind of function?? :-s Don't know if it matters that the one I found is on Amazon UK, and your link is for the US (I'm in the UK)... so yeah, anymore thoughts please?

Thinka 40 Posting Whiz Team Colleague

Yea DemonicGoldfish I agree with Titans on the overclocking issue. If you've got a 2GB 800Mhz RAM and you're running on Core 2 Duo, (amazing specs might I add), really overclocking could be like trying to make the string on an already fine bow, finer - you could end up snapping it! Hehe seriously mate you've got a great system, enjoy it.

Thinka 40 Posting Whiz Team Colleague

OK seriously "Nutty Professor"

Thinka 40 Posting Whiz Team Colleague

3 :-p

Thinka 40 Posting Whiz Team Colleague

Hi Peter, I have Ad-Aware SE Personal as well on my computer, and I've just done an update. It took a while (by this I mean about 2-3) minutes for it to connect to the Lavasoft Server, but then it did and found updates dated 17/01/2007, which I have now installed successfully.

Try checking for updates again mate, maybe you just need to be a bit patient with the time it takes to connect to the server because I almost cancelled it cos I thought something was wrong.

Hope that helps

Thinka 40 Posting Whiz Team Colleague

Ask her to go to internetfrog.com (it has to be from her computer), where she can run a test to see the speed of her broadband, and also how fast she should be able to download and upload to the net. I've only seen problems like that with wireless connections though, and you say that hers is wired, so I can't think of anything else.
She could also contact her internet Service Provider to be sure that everything is right with them.

Sorry can't be of anymore help;)

Thinka 40 Posting Whiz Team Colleague

Hi sophe,
First of all, how/when did the problem start? I'm presuming you haven't had it since forever, so it might have been that something you changed, or installed, or updated, may have tampered with the settings. Can't really say much more apart from try to reverse any changes you might have made to your system either by System Restore, or just uninstalling the relevant software.

Good luck!

Thinka 40 Posting Whiz Team Colleague

Hi there, hope someone can help, I was just wondering WHERE it is possible to get such an adapter (i think they are VGA adapters) as I have mentioned above, one that will at least connect ur monitor to your PS2 so that you can use it as TV. I gather that there are adapters that will allow you to do this AND still have your CPU connected to your monitor at the same time, but I've only seen one online and I'm not sure as to its quality.. so is there anyone with some experience that can advise? What implications will it have (if any) on the screen quality?

Also I think the only other alternative to not getting an adapter is a TV PCI card? Is this strictly true, and can a PS2 be connected to a TV card?