death_oclock 103 Posting Whiz

Your original code is almost right. Just take a look at your structure definition. You want comments to hold a string, but you have defined it as a single character. That's why you're getting an error with gets.

Now, gets won't allocate the variable for you so you'll need to use malloc for comments too. Or you could define it statically like in your second example.

If the user inputs more data than comments can hold, you'll get undefined (and probably unwanted) behavior, so use fgets(currentC->comments, size, stdin); where size is the number of bytes you've allocated for comments .

death_oclock 103 Posting Whiz

There is a single arithmetic operation you can use to convert the ranges 0-89, 90-179, 180-269, 270-359 into the values 0, 1, 2, 3, respectively. The result represents the quadrant; 0 would be the first quadrant.

death_oclock 103 Posting Whiz

There are a few other considerations when using malloc . The function returns NULL if memory can't be allocated, so you need to test for that possibility:

void *mem = malloc(size);
if(mem == NULL) // or if(!mem)
{
    // error handling
}

You also need to free the memory when you're done:

free(mem);
mem = NULL;

These are generic examples that you'll have to modify for your program.

This wikipedia article has much more information if you're interested.

death_oclock 103 Posting Whiz

I guess I should have done more research before I posted. I found a solution on this page describing tag schemas.

death_oclock 103 Posting Whiz

So I have a table containing various software and a table containing various features. Each software entry need to have a list of features.

Here's where it gets tricky:
In my application, I need to be able to select a software entry if it has all the features in a list. An example: a text editor has syntax highlighting, hex editing, and a plugin manager. I want to select it only if it has syntax highlighting and a plugin manager.

The obvious solution would be to store a list of feature IDs in a comma-separated string. But then I'd have to do all the matching within the application, which would be pretty slow (I'm using PHP), not to mention I'd have to select ALL the software first.

Any better solutions?

death_oclock 103 Posting Whiz

You already did. Declaration: int **x_transpose; Initialization: x_transpose= transpose(array,nrows,ncolumns);

death_oclock 103 Posting Whiz

int arrays do not have a remove method. You may be thinking of the List class. You will have to implement that feature yourself. When you find a match, you will need another loop to shift the remaining elements one index forward. Also your matching logic is flawed. What if the duplicate temperatures are spaced apart?

death_oclock 103 Posting Whiz

Where are you initializing vowelCount? Anyway, you could just reuse the vowelNum method and do something like this: return word.length() - vowelNum();

death_oclock 103 Posting Whiz

I would honestly like to know why PlottingPanel would have no idea it has been pressed.

Because PlottingWindow implements MouseListener and PlottingPanel does not. PlottingPanel will not receive the MouseEvent.

death_oclock 103 Posting Whiz

You can call myGuiWindow.add(component); from any class as long as it has a reference to the window.

death_oclock 103 Posting Whiz

Akill10: I think the reason he defined setStartX in PlottingPanel is so that the data would only be sent after a mouse click. With your solution, PlottingPanel has no idea if the mouse has been clicked yet, and therefore startX would likely be zero (or undefined or something).

death_oclock 103 Posting Whiz

You don't need to copy a new array each time. Just change the value of n.

death_oclock 103 Posting Whiz

This program uses many outdated practices (void main, clrscr, kbhit) and should not be used as an example by anyone.

WaltP commented: So true... +15
death_oclock 103 Posting Whiz

You don't need to allocate memory for x_transpose. After the line x_transpose= transpose(array,nrows,ncolumns); x_transpose points to the same block of memory that was allocated for y. You do need to free all of this memory before the program closes, however.

death_oclock 103 Posting Whiz

Why do you need to write this recursively? It would be much simpler with a single loop. Also, recursive methods tend to be much slower and more memory-intensive than their iterative equivalents.

death_oclock 103 Posting Whiz

Try using printf("Greetings, human!"); (just a guess, honestly)

death_oclock 103 Posting Whiz
death_oclock 103 Posting Whiz

Based on what you already wrote, you know how to pass in parameters and call methods. You should be able to figure this one out.

death_oclock 103 Posting Whiz
death_oclock 103 Posting Whiz

JPanel doesn't know the value of startX yet, so you can't pass that value in as a parameter. Instead, you should pass in the JFrame object and call the getStartX method inside of setStartX.

death_oclock 103 Posting Whiz

Whether you like it or not, every key press involves several method calls to send the key event to the proper object. If you don't want to send data on every key press then you can create a buffer (array) to store key strokes and only send it when the buffer is full.

death_oclock 103 Posting Whiz

startX and startY should be private or protected.

public int getStartX()
{
	return startX;
}

I trust you can write the method for startY on your own.

death_oclock 103 Posting Whiz

Your hottestDay method does the same exact thing as highestTemp. Which variable represents the current day you are checking?

In checkDuplicates, your outer loop will only run once while the inner loop will run 48 times. The variable x will never change from 0. Use your previous for loops as a guide.

removeDuplicates will be easier once you get checkDuplicates working.

death_oclock 103 Posting Whiz

I just wrote a program that plays various drum sounds when certain keys are pressed. It works for the most part but, when two keys are pressed at the same time, only one sound plays. Both key presses are received, however. I am using the Clip class which allegedly supports simultaneous playing. Here's the relevant code:

Input.java

// input handling method
// keyMap is type HashMap<Integer, String>
// audio is instance of Audio
public void keyPressed(KeyEvent e)
{
	Integer code = new Integer(e.getKeyCode());
	
	String sound = keyMap.get(code);
	if(sound != null)
		audio.startSound(sound);
	
	e.consume();
}

Audio.java

// clip playing method
// soundMap is type HashMap<String, Clip>
public void startSound(String id)
{
	Clip sound = soundMap.get(id);
	if(sound != null)
	{
		sound.setFramePosition(0);
		sound.start();
	}
}

I can post any other methods/definitions if needed.

death_oclock 103 Posting Whiz

This tutorial will tell you which directories to add. It is based on Code::Blocks but you should be able to find these options within Dev-C++ easily enough.

death_oclock 103 Posting Whiz

Google ("c sound library") returns plenty of good results. You can find tutorials/documentation for any of them. Check out the features to find which library fits your needs best.

death_oclock 103 Posting Whiz

You will have to use COM objects. MSDN provides a programming guide and a reference. These can be hard to understand so you may want to find a tutorial on google..

death_oclock 103 Posting Whiz

I honestly don't know why the write operation is inserting instead of overwriting. I can point out that you should put l = file.getFilePointer(); BEFORE you you read the line because the read operation will move the pointer to after the line.

death_oclock 103 Posting Whiz

We can help you better if you post the relevant code as well.

death_oclock 103 Posting Whiz

Thanks, the "working directory" option was the one I was looking for.

death_oclock 103 Posting Whiz

I can't find, within my project directories, any option to specify where I want my .exe to start in. I want to do this for that sake of .dll and other file references. Any help?

death_oclock 103 Posting Whiz

It would help if you provided a sample file structure and the output from your program.

death_oclock 103 Posting Whiz

Next time, please use code tags and edit your original post instead of creating a new one.

The solution for your question: simply encase the code you posted in another loop. I'll leave it up to you to figure out the best outer loop for this situation.

death_oclock 103 Posting Whiz

I got something similar but did you use a square matrix to derive your result?

I wouldn't say I "derived" it from anything, possibly because I don't quite understand the question. The idea came from a simple file-explorer GUI I was working on.

death_oclock 103 Posting Whiz

I am unsure of the efficiency of my method, but I like to use (if using one loop is really a big deal; usually the choice is out of ease):

for(int i = 0; i < ROWS * COLS; i++)
{
    printf("%i ", arr[i/ROWS][i%COLS]);
}
death_oclock 103 Posting Whiz

I would suggest creating at least one function, getPixel, to make your code more readable. Post this new code and i'll try to take a look.

death_oclock 103 Posting Whiz

Do you have the exact wording of the problem? You cannot turn an unordered list into an ordered one without sorting it.

death_oclock 103 Posting Whiz

A good beginning sort algorithm is the Bubble Sort

death_oclock 103 Posting Whiz

We can't correctly solve your problem without more information. Post the definitions of your variables and we'll see.

death_oclock 103 Posting Whiz
death_oclock 103 Posting Whiz

My apologies, my advice was not very good. Your original solution is very close but with a few minor tweaks.

Your main should include this (note that N is no longer defined as a pointer and you are not passing in it's address to Display).

int *a, N;
Input(a,&N);
Display(a,N);

Now Input() has to accept a pointer N as one parameter. Inside the function, you need to set the actual value that N points to. Pointers can be confusing at first, lets see what you come up with.

death_oclock 103 Posting Whiz

What output do you get?

death_oclock 103 Posting Whiz
int main()
{
  int *a, *N;
  Input(a,&N);
  Display(a,&N);
  getch();
  return 0;
}

&N really means "the address of the pointer N". Your code shouldn't even compile because Input() expects an int for the second parameter. So what if Input() returns the value of N?

death_oclock 103 Posting Whiz

Oh wow, I forgot about the second call myself. Jepthah: point taken.

death_oclock 103 Posting Whiz

"Being cute" was not my intention. I was thinking of efficiency at the time. And while I appreciate the suggestion, it doesn't help my immediate problem.

death_oclock 103 Posting Whiz

I hate to sound like a prick but... using fscanf is generally a bad idea. There are plenty of reasons, but a big one is that most people don't really understand what its doing. Therefore it usually only works with carefully formatted input. Or by accident.

death_oclock 103 Posting Whiz

A search through the WinAPI turned nothing like what you want. My guess is that those are things only XP knows and keeps them secret. I could be quite wrong though.

death_oclock 103 Posting Whiz

fgets and strtok would be good places to start. Do you know how many strings you will be reading? If you don't it will make the array part a little more difficult.

death_oclock 103 Posting Whiz

I'm getting an error (unhandled exception writing address so and so) trying to modify a string. It gets weirder though. Let me show what i've got:

--Main.c--

#include "stdafx.h"
#include "commands.h"

int main(int argc, char* argv[])
{
	char word[256];
	int id;

	strcpy(word, "move");
	strToUpper(word);
	printf("%s", word);
	id = getCommandId(word);

	if(id == -1)
		perror("Error");
	else if(id == 0)
		printf("No such command.");
	else
		printf("ID: %d\n", getCommandId("move"));

	getchar();
	return 0;
}

--commands.h--

#pragma once

#define COMMAND_MOVE 1
#define COMMAND_TAKE 2
#define COMMAND_LOOK 3

int getCommandId(char *word);
void strToUpper(char *str);

And --commands.c--

#include "stdafx.h"
#include "commands.h"

void strToUpper(char *str)
{
	int i = 0;
	while(str[i] != '\0')
	{
		str[i++] &= 0xDF; //reset bit 5
	}
}

int getCommandId(char *word)
{
	FILE *fp;
	char buf[256];
	char *tok;
	int i = 0;

	fp = fopen("commands.dat", "r");
	if(fp == NULL)
		return -1;
	
	strToUpper(word);

	while(++i)
	{
		if(fgets(buf, 255, fp) == NULL)
			break;

		tok = strtok(buf, " ");
		while(tok != NULL)
		{
			if(strcmp(tok, word) == 0)
				return i;

			tok = strtok(NULL, " ");
		}
	}

	return 0;
}

Nothing real exciting happens with the call to strToUpper in main, other than the string being capitalized. Then getCommandId is called, and therefore strToUpper is too, with the same pointer word as before. Only this time, I get the nasty error described at the top of my post. Thoughts?

death_oclock 103 Posting Whiz

If you already know how to use strtok, why did you use that in your topic title? Well anyway, I think you want something like this:

int r, c;
int arr[numRows][numCols];
while(/*there's another line*/)
{
  for(c = 0; c < 4 /*num cols*/; c++)
  {
    arr[r][c] = /*data read*/;
  }
  r++;
}