death_oclock 103 Posting Whiz

Lets just take a look at this code:

ptr=n*(malloc(sizeof(n));
ptr=head;
scanf("%d",&ptr->data);
head=ptr->data;
ptr=ptr->next;

You don't need line 1 because you just set it to point to a space of memory that has already been allocated ( head=n*(malloc(sizeof(n)); ). Lines 2 and 3 look alright to me. Line 4 doesn't work (I sure hope that doesn't compile) because head is a pointer (to a struct node) and you are trying to assign to it a plain old integer. Since ptr and head point to the same thing, line 3 takes care of what you want. Line 5 may seem to make sense, but it actually does nothing. At the end of this function call, ptr will be deleted. A few final notes: the first time you call this function, it will only allocate memory, not load any data. And you seem to be missing a closing } for the function.

death_oclock 103 Posting Whiz

Just a tip: since you are reallocating new memory when you run out of space, you probably want to use realloc. This will keep all the data you had copied into your array previously.

death_oclock 103 Posting Whiz

Ark's approach is much neater and most likely works. Your solution is very hard to read; the looping approach makes more sense.

death_oclock 103 Posting Whiz

Purely for the sake of simplicity, I would go with this route (doesn't use a second set of variables):

int main( int argc, char *argv[] ){
  int *numberlist, i, n, min, max ;

  n = atoi( argv[1] );
  numberlist = ( int * ) malloc( n * sizeof( int ) );
  for( i = 0; i < n; i++ ) numberlist[i] == rand() % n ;

  minmax( numberlist, n, &min, &max );
death_oclock 103 Posting Whiz

I am modifying a myspace page so the only tag I added is the <style> tag shown above.

death_oclock 103 Posting Whiz

I tested it myself and it worked regardless of the resolution. What browser did this occur in?

death_oclock 103 Posting Whiz

Firefox has beaten out IE (thankfully) but there is still too large a demographic of IE users to just ignore. Opacity hasn't quite caught on as standard yet (I doubt anything will for IE) so the first definition is just for IE, the second for most other browsers. And I haven't had this problem designing other sites before, this is the first time I've seen something so blatantly broken by a specific browser.

death_oclock 103 Posting Whiz

I have designed my page using Firefox and it looks exactly as I would expect it to, colors consistent with my design using Photoshop. When I view the page in Internet Explorer, all the colors are changed. It looks as if everything has a slight gray layer over it making it look dreary and "gross." Even the background image looks very different, it is lighter and brown-ish. The transparency I applied doesn't have any effect (yes, I added the IE "filter" property for alpha-opacity). The CSS I have added (in addition to the existing myspace styles) is here:

<style type="text/css">
.bodyContent
{
  background-color: 1e190c;
  background-image: url('http://img15.imageshack.us/img15/706/58119117.jpg');
  background-position: center;
  background-repeat: repeat-y;
  filter: alpha(opacity=80);
  opacity: 0.8;
}

.bodyContent a, .bodyContent a:link, .bodyContent a:active, .bodyContent a:visited
{
  color: ffffff;
  text-decoration:
  underline;
}
.bodyContent a:hover
{
  color: ff6600;
}

.bodyContent br
{
  line-height: 20px;
}

.bodyContent table
{
  border-style: solid;
  border-color: ffffff;
  border-width: 0px 1px 0px 1px;
  background-color: 3c0909;
}
.bodyContent table table table td
{
  border-width: 0px;
}
.bodyContent table table table table
{
  border-spacing: 1px;
}
.bodyContent table[id="headerTable"] td
{
  background-color: 2358b8;
}
.bodyContent table[id="musicJVNav"] td
{
  background-color: transparent;
}

.bodyContent tr, .bodyContent td, .bodyContent table table, .bodyContent table table td
{
  color: ffffff;
  border-width: 0px;
  background-color: transparent;
}

.bodyContent table table table table table strong
{
  color: ffffff;
}
.bodyContent table table table table
{
  border-width: 0px;
  background-color: transparent;
  padding: 0px;
  margin: 0px;
  background-image: none;
}
.bodyContent table table table table td
{
  padding: 0px;
  margin: 0px;
} …
death_oclock 103 Posting Whiz

There is not a way I know to do this with plain old HTML. Are you using ASP or PHP? You can force the browser to request download rather than just opening the file using some header info.

death_oclock 103 Posting Whiz

Are you trying to emulate a DOS environment using C? Post the relevant code you have already, what it is supposed to do, and what it is doing wrong.

death_oclock 103 Posting Whiz

Not really. Removing the "px" changes nothing. And 0px really doesn't make sense to you? How else should you remove a border inherited from lower down in the cascade?

death_oclock 103 Posting Whiz

I need to have my background image span the entire length of the page without using the BODY element, here's why: I separated the image into left and right sections so even for different resolutions, the left image will always be on the left, and same with the right. Because of this, I have to use two DIVs, each with one part of the image. The problem is, I haven't seen any way to get them to span the entire height of the page. Setting width: 100%; only sets these to 100% of the viewport. Any ideas?

Edit: here is the CSS I currently have (for those specific parts):

.bodyContent .bg_l
{
  position: absolute;
  z-index: -1;
  top: 0px;
  left: 0px;
  height: 100%;
  width: 500px;
  background-image: url('http://img22.imageshack.us/img22/2778/bgl.jpg');
  background-repeat: repeat-y;
}
.bodyContent .bg_r
{
  position: absolute;
  z-index: -1;
  top: 0px;
  right: 0px;
  height: 100%;
  width: 500px;
  background-image: url('http://img15.imageshack.us/img15/5810/bgrf.jpg');
  background-repeat: repeat-y;
}

Edit again: I just realized that in IE (horrible thing that it is) the background won't span any of the page except for a small, ~15px part at the top. If you want to take a look at this, here is the page.

death_oclock 103 Posting Whiz

Sorry, I should have posted the types I defined; REALIZATION is a pointer in itself, so in that aspect the program works. What is the benefit to clearing a block of memory before freeing it though?

death_oclock 103 Posting Whiz

Nevermind, I caught it. I didn't free pitches inside randomActualChord() .

death_oclock 103 Posting Whiz

My program is getting hung up somewhere in the function evolveRealization and while it is stuck its memory usage is increasing by around 1MB per second! While it is building up generations, it was designed to only use the most recent one, and the old ones should be freed. So where is this memory leak coming from?

#include "stdafx.h"
#include "types.h"
#include "pitch.h"
#include "chord.h"
#include "phrase.h"
#include "realization.h"

ACTUAL_CHORD randomActualChord(CHORD_SYMBOL *chordSymbol)
{
	ACTUAL_CHORD actualChord;
	PITCH *pitches;

	pitches = chordSymbolPitches(chordSymbol);

	actualChord.soprano = pitches[rand() % ((chordSymbol->quality >= major7) ? 4 : 3)];
	actualChord.alto = pitches[rand() % ((chordSymbol->quality >= major7) ? 4 : 3)];
	actualChord.tenor = pitches[rand() % ((chordSymbol->quality >= major7) ? 4 : 3)];
	actualChord.bass = pitches[rand() % ((chordSymbol->quality >= major7) ? 4 : 3)];

	return actualChord;
}

//return pointer must be freed
ACTUAL_CHORD *randomRealization(int length, CHORD_SYMBOL *sequence)
{
	ACTUAL_CHORD *realization;
	int i;

	realization = malloc(sizeof(ACTUAL_CHORD) * length);
	if(!realization)
		return NULL;

	for(i = 0; i < length; i++)
	{
		realization[i] = randomActualChord(&sequence[i]);
	}

	return realization;
}

int calcFitnessRealization(int length, REALIZATION realization, SEQUENCE sequence)
{
	PITCH *pitches;
	int fitness = 0;
	int count;
	int diff;
	bool bad;
	int i;

	for(i = 0; i < length; i++)
	{
		bad = false;

		pitches = chordSymbolPitches(&sequence[i]);
		if(!pitches)
			return -1;

		if(!pitchEquals(realization[i].bass, pitches[sequence[i].inversion]))
			bad = true; //wrong inversion
		
		else if(!pitchEquals(realization[i].soprano, pitches[0]) &&
				!pitchEquals(realization[i].alto, pitches[0]) &&
				!pitchEquals(realization[i].tenor, pitches[0]) &&
				!pitchEquals(realization[i].bass, pitches[0]))
			bad = true; //missing root of the chord

		else if(!pitchEquals(realization[i].soprano, pitches[1]) &&
				!pitchEquals(realization[i].alto, pitches[1]) &&
				!pitchEquals(realization[i].tenor, pitches[1]) &&
				!pitchEquals(realization[i].bass, pitches[1]))
			bad = true; //missing third of …
death_oclock 103 Posting Whiz

Well this isn't a terribly performance-intensive part of my program, and I have to submit the whole bloody thing by friday, so maybe i'll get to it another time, and post the results if anyone is still intersted.

death_oclock 103 Posting Whiz

Would that solution be more or less efficient than calling a function like this on the data before writing:

void swapEndianL(unsigned int *x)
{
	*x = (*x>>24) |
	 ((*x << 8) & 0x00FF0000) |
	 ((*x >> 8) & 0x0000FF00) |
	 (*x << 24);
}
death_oclock 103 Posting Whiz

Is there any way to force fwrite() to write in big-endian format no matter what? I am trying to write a MIDI file and they are always big-endian. Converting every value I write to big endian beforehand would be extremely tedious. Ideas?

death_oclock 103 Posting Whiz

I see, thank you.

death_oclock 103 Posting Whiz

If you like finding new functions, you should definitely take a look at the php function reference. By the way, I love discovering things in languages too.

death_oclock 103 Posting Whiz

I had forgotten about calloc for the longest time, but I was recently reminded of it. Now i'm curious, what would be the difference between malloc(numElems * elemSize); and calloc(numElems, elemSize); ? If my knowledge of arrays is correct, there shouldn't be any difference in the memory allocated.

death_oclock 103 Posting Whiz

For the purpose of adding a one dimensional array works well enough in representing a matrix. For more complicated operations though, it would likely be easier to define a matrix like int mat[rows][cols];

death_oclock 103 Posting Whiz

To quote myself for emphasis:

(after some error checking/security checks!!!)

In the page inside the iframe, thoroughly check the css file requested. I would make sure it is one of a select number of specific filenames, rather than checking just the extension, etc.

death_oclock 103 Posting Whiz

No, you don't pass in the filename; you pass an already opened file pointer (FILE *).

death_oclock 103 Posting Whiz

That's true. You don't seem to be getting the point here. A string is an array of chars. An array of strings (multiple names) must be an array of arrays of string. Therefore you have the two dimensional array csurfer described. You should really take a look at the code provided and try to understand it. You would benefit from going back to the basics as well. Pointers are a crucial part of C...

death_oclock 103 Posting Whiz

Strings (if you do it the C way) should have a null character ('\0') to show where the end of the string is. Change your definitions to look like this:

char username[15] = {'r','g','f','i','r','e','f','l','y','2','4','\0'};
// or
char *username = "rgfirefly24"; //automatically adds the '\0'
death_oclock 103 Posting Whiz

Well since this is a PHP forum, i'll give you a PHP solution. You could pass the css file for the iframe to use in the url like so:

<iframe id="pframe" width="'.$game['iframewidth'].'" height="'.($game['iframeheight'] + 20).'" src="'.$path.'?style='.$style.'" frameborder="0" scrolling="no" align="middle"></iframe>

where style is the css file. In the iframe page, get this value from the $_GET superglobal and (after some error checking/security checks!!!) print the reference to this external stylesheet.

almostbob commented: Thanks Bloke, hadnt seen this approach before, way more efficient than duplicating content between domains +1
death_oclock 103 Posting Whiz

Read up on common controls.

death_oclock 103 Posting Whiz

As soon as I looked at the code, the ugly void main was staring me in the face. Please fix it in your code, so I can rest easier.

death_oclock 103 Posting Whiz

You can replace that with a call to rewind(infile).

death_oclock 103 Posting Whiz

You can't define variables in the for loop header, so you need to put int i; somewhere else.

death_oclock 103 Posting Whiz

char stu_name[10]; is defining just one string that can hold 9 characters. You should define it like char stu_names[10][NAME_LENGTH]; . And no, you should never add system("pause");

death_oclock 103 Posting Whiz

O(N...whatever) is Big O Notation. It is a way of expressing the efficiency (often the "worst case" efficiency) of an algorithm based on the size of its input. O(N) is a linear efficiency, other common ones are O(N^2) and O(log(N)). Note that coefficients are not expressed; you would not say O(2N), just O(N).

death_oclock 103 Posting Whiz

Since this is for a game (high performance required) I would recommend you look at DirectDraw. A decent tutorial I know is here: www.falloutsoftware.com

death_oclock 103 Posting Whiz

Yeah, that's really not a wonderful idea. Why don't you base your web blog on a database, and use a C++ program to connect to the database and add a new post that way? Your method depends way too much on hoping that everything will go as planned (window will open where you want it to, etc.). Also, you aren't even using the variables you set to the duration of each click.

death_oclock 103 Posting Whiz

That would be a great plan if you were trying to write bad-looking and terribly inflexible code. You can do this with a loop, however, which will let you find the maximum of any amount of numbers you want. You should keep a variable holding the value that is the max so far and each time you find a value that is greater than the max, set the max to this new value.

death_oclock 103 Posting Whiz

Why, in any circumstance, would resurrecting a four year old thread to ask a vague question using bad grammar (forget english grammar, I mean C grammar. C doesn't have "commands") be a good idea? Hmmm...

death_oclock 103 Posting Whiz

A good way to implement this is giving each subcategory a reference (field) to the parent category's unique ID. You can do this with an auto-incrementing int field. A root category can just have the parent -1 (for example) to specify that it is at the top level.

death_oclock 103 Posting Whiz

What is your problem? Compile errors? Your node class seems a little off to me also. What are the other pointers supposed to be for? Most linked lists only have pointers to the next and/or previous item (see http://en.wikipedia.org/wiki/Linked_list)

death_oclock 103 Posting Whiz

Try posting a sample file generated by your program. Off the top of my head, I can't think of anything that would cause this.

death_oclock 103 Posting Whiz

Have you tried uploading it again? Tried uploading other files? This seems to have nothing to do with your C++ program.

death_oclock 103 Posting Whiz

Think about array indices. To write them from beginning to end, you would start at 0 and go to arrayLength - 1. How might you do the opposite?

death_oclock 103 Posting Whiz

The browser wouldn't make a difference if you use the same one to view pages on you local server as on your byethost server. Have you looked at the html source of both pages? I use byethost myself and uploading a file has never done this.

death_oclock 103 Posting Whiz

Does your page try to run the .exe to generate the new page? Byethost disables the running of executables for some pretty important security reasons.

death_oclock 103 Posting Whiz

Take a look at the aspell dictionary.

death_oclock 103 Posting Whiz

This thread was about connecting to Access, not MySQL. ODBC allows you to connect to databases with a level of abstraction over the specific database you use, letting you not have to worry about individual APIs.

death_oclock 103 Posting Whiz

Our binary search

Does this mean that you have one implementation already? Try posting it so we can see what it is you need to modify.

death_oclock 103 Posting Whiz

But it is an alternative to adding a 0 border around the main grid. To me, edge checking would make more sense.

death_oclock 103 Posting Whiz

Ah, I wasn't saying you always bash the system function, but whenever it appears in code just about everyone else goes crazy.

death_oclock 103 Posting Whiz

Do you already have the part of the query that matches the site? Add to that (with an AND clause) a MATCH(field) AGAINST('value') as demonstrated in the link I gave you.