Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Sexxxy Sophitia
Aug 28, 2008

Anime Baby
So I have to write a program to explain bytes and bits and int values in C
but I'm having trouble getting exponents to work. Here's an example of what I'm doing.

code:
printf("A long value stores %d byte(s)\n",sizeof(w));
printf("Which means it can store %d bits.\n",sizeof(w)*8);
printf("That means it can store %d values.\n",(pow(2,(sizeof(w)*8))));
Should I be doing this differently because it's returning the wrong values.

Adbot
ADBOT LOVES YOU

csammis
Aug 26, 2003

Mental Institution

Sexxxy Sophitia posted:

So I have to write a program to explain bytes and bits and int values in C
but I'm having trouble getting exponents to work. Here's an example of what I'm doing.

code:
printf("A long value stores %d byte(s)\n",sizeof(w));
printf("Which means it can store %d bits.\n",sizeof(w)*8);
printf("That means it can store %d values.\n",(pow(2,(sizeof(w)*8))));
Should I be doing this differently because it's returning the wrong values.

I assume somewhere you've declared a long w, right? Try sizeof(long) instead. If it's still returning the "wrong" values, post what it is returning and we'll be able to tell you why it's right :)

e: Oh, only the exponent thing is wrong? What is it returning?

e2: Why would you tell us it's returning the wrong values without saying what those are in the first place? :(

Sexxxy Sophitia
Aug 28, 2008

Anime Baby
The return I get is:
code:
LONG
A long value stores 4 byte(s)
Which means it can store 32 bits.
That means it can store 1106247680 values.
I can post the whole program if that would help.

csammis posted:

e2: Why would you tell us it's returning the wrong values without saying what those are in the first place? :(

I don't know :D

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Sexxxy Sophitia posted:

code:
printf("That means it can store %d values.\n",(pow(2,(sizeof(w)*8))));

%d wants an int parameter. Even if pow returned an int instead of a double, you can't fit the number you want in an int, by definition. Replace %d in this line with %.0f and it should work.

Sexxxy Sophitia
Aug 28, 2008

Anime Baby

ShoulderDaemon posted:

%d wants an int parameter. Even if pow returned an int instead of a double, you can't fit the number you want in an int, by definition. Replace %d in this line with %.0f and it should work.

That can't be the only problem because it happens with my char too, which will fit in an int.

Okay, here's the sections I need help with

code:
#include <stdio.h>
#include <math.h>

int main(){

int x;
char y;
short z;
long w;

/*Crap that doesn't apply goes here*/

printf("INT\n");
printf("An int value stores %d byte(s)\n",sizeof(x));
printf("Which means it can store %d bits.\n",sizeof(x)*8);
printf("That means it can store %d values.\n",pow(2,(sizeof(x)*8)));

printf("CHAR\n");
printf("A char value stores %d byte(s)\n",sizeof(y));
printf("Which means it can store %d bits.\n",sizeof(y)*8);
printf("That means it can store %d values.\n",pow(2,(sizeof(y)*8)));

printf("SHORT\n");
printf("A short value stores %d byte(s)\n",sizeof(z));
printf("Which means it can store %d bits.\n",sizeof(z)*8);
printf("That means it can store %d values.\n",pow(2,(sizeof(z)*8)));

printf("LONG\n");
printf("A long value stores %d byte(s)\n",sizeof(w));
printf("Which means it can store %d bits.\n",sizeof(w)*8);
printf("That means it can store %d values.\n",(pow(2,(sizeof(w)*8))));
Here's what it's returning:

code:
INT
An int value stores 4 byte(s)
Which means it can store 32 bits.
That means it can store 1106247680 values.
CHAR
A char value stores 1 byte(s)
Which means it can store 8 bits.
That means it can store 1081081856 values.
SHORT
A short value stores 2 byte(s)
Which means it can store 16 bits.
That means it can store 1089470464 values.
LONG
A long value stores 4 byte(s)
Which means it can store 32 bits.
That means it can store 1106247680 values.

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
pow() returns a double. Using %d to print a double will give you incorrect output. That is the only problem.

Rocko Bonaparte
Mar 12, 2002

Every day is Friday!
csammis, I started moving over to jface. I don't see an explicit listener for doing sorting, so I don't think there's a spot where I can disable table refresh when moving the rows around. Still, with about 500 entries it's taking about two seconds to sort by ~4-letter strings (stock symbols). Doesn't that seem like a long time?

I could dismiss it and eat the sort hit, but I plan to have many more entries in that table by the time I'm done, which will put an annoying sort penalty on me.

Sexxxy Sophitia
Aug 28, 2008

Anime Baby
Okay so that worked, now how do i get this to work?

code:
long w, xx, xy, xz, xw;
xx = pow(2,(sizeof(x)*8));
xy = pow(2,(sizeof(y)*8));
xz = pow(2,(sizeof(z)*8));
xw = pow(2,(sizeof(w)*8));


printf("To find the range of an unsigned int\nYou would take the number of values it can store %.0f\nAnd subtract one to get %.0f.\n",xx,xx-1);
frintf("To find the range of a signed int\nYou would again start with the number of values it can store %.0f.\nThis time you divide by two and get %0f.\nPut a negative sign in front of that number and you have the lowest value -%.0f.\nSubtract one from that value and you have the highest value %.0f.\n\n",xx,xx/2,xx/2,xx/2-1);
It returns this

p66.c: In function `main':
p66.c:10: warning: overflow in implicit constant conversion
p66.c:13: warning: overflow in implicit constant conversion
Undefined first referenced
symbol in file
frintf /var/tmp//ccqdI89E.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

EDIT: So this post is obnoxiously wide is ther a better way to post that?

Sexxxy Sophitia fucked around with this message at 17:45 on Oct 30, 2008

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
It's the same problem: pow() returns a double, but none of those variables that you're assigning the results to are doubles.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender
You also now have a typo: frintf instead of printf.

Sexxxy Sophitia
Aug 28, 2008

Anime Baby
Okay I got it, thanks guys.

Is there a way to write a program that will finger just my classmates?

if I have a users file that has the usernames of the people in my class

finger
the if any of the usernames I have are in the first field, print the first and second field of that line in the finger, else printf "No one is online"

yippee cahier
Mar 28, 2005

Does anyone have any DNG experience? I have a raw bayer pattern and am trying to wrap it in a very basic DNG file so I can demosaic it later. Using libtiff I have managed to make a TIFF file containing the bayer pattern. What are the bare minimum TIFF tags I need to add to this file to so it can be identified as a DNG?

csammis
Aug 26, 2003

Mental Institution

sund posted:

Does anyone have any DNG experience? I have a raw bayer pattern and am trying to wrap it in a very basic DNG file so I can demosaic it later. Using libtiff I have managed to make a TIFF file containing the bayer pattern. What are the bare minimum TIFF tags I need to add to this file to so it can be identified as a DNG?

I assume you're talking about Digital Negative format here? Maybe the Adobe file specification will tell you what you need to know.

fankey
Aug 31, 2001

sund posted:

Does anyone have any DNG experience? I have a raw bayer pattern and am trying to wrap it in a very basic DNG file so I can demosaic it later. Using libtiff I have managed to make a TIFF file containing the bayer pattern. What are the bare minimum TIFF tags I need to add to this file to so it can be identified as a DNG?
dcraw might be of some use. He has some sample code on that page to write out DNG files.

ten_twentyfour
Jan 24, 2008

nvm.

ten_twentyfour fucked around with this message at 23:03 on Oct 30, 2008

squiffy
Aug 3, 2007
Rebus: TTT
I'm writing a small plugin for Audacity in Nyquist. Nyquist uses LISP.
The plugin should delete regular intervals from audio specified by the user.
I'm having awful trouble getting the correct amount of audio to be deleted and the loops just don't seem to work at all.

code:
;nyquist plug-in
;version 1
;type process
;name "Delete Regular Intervals..."
;action "Deleting..."
;control interval "Every" real "s" 0.1 0.001 1.0
;control delAmount "Delete this amount" real "s" 0.1 0.001 1.0

(defun delInterval (j d r) ; delInterval(interval, deleteAmount, sound source)
	(setf s-length (* (get-duration 1)))
	(setf maxAmount (truncate (/ s-length interval)))
	(setf chan0 (const 0 0)) ;init chan0
	(dotimes (n (- maxAmount 1) chan0) 
		(setf chan (extract-abs (+ (* n j) d) (* j (+ n 1)) r))
		(setf chan0 (seq chan0 chan))
	)
)

(if (arrayp s) ;Splits stereo source into l and r channels
	(vector 
	(delInterval interval delAmount (aref s 0))
	(delInterval interval delAmount (aref s 1)))
    (delInterval interval delAmount s) ;Mono source
)               
Essentially the behaviour of the plugin is to extract slices of the audio at regular intervals and sequentially place them in a new variable.
This is as far as I have got over the past few days and it's driving me insane. I think it may be a problem with the extract function, or perhaps it's a very simple error in the logic of my implementation.
I don't hold out any hope for anyone to know LISP or even Nyquist, but thanks anyway!

Chuu
Sep 11, 2004

Grimey Drawer
My brain is completely melted after working 60 hours on some stupid thread code and I can't write a simple algorithm. Halp.

An application represent numbers as two integers. One is the value, the other is the decimal location.

Examples:

2.21 : VALUE(221) LOC(2)
504 : VALUE(504) LOC(0)
3.442 : VALUE(3442) LOC (3)

I need a good way to take a double and convert it into two a value/loc combo. Originally I just did this:

code:
(c++)

double price = thread.getValue();
int decloc = 0;
while( price - ((int)price) != 0)
{
	price*=10;
	decloc++;
}
This code does not work for because of double's native representation that doesn't correspond well to Decimal, which are easier to gut check then explain (3.43 -> 3.43000000000001 -> 3430000000000001 * 10 -> +inf).

Valid range of double values is from 0000.1 to 99999.

I'm assuming just adding an /epsilon value and checking the remainder against it is all I need to fix this, but my brain is so fried I can't formulate it.

Any help?

Chuu fucked around with this message at 04:49 on Oct 31, 2008

Marx Headroom
May 10, 2007

AT LAST! A show with nonono commercials!
Fallen Rib
I hit a roadblock on my very first Haskell program:

http://www.quickfilepost.com/download.do?get=1f573e1d8ff015815ea5022923b120d3

code:
Prelude> :load scan.hs
[1 of 1] Compiling Main             ( scan.hs, interpreted )

scan.hs:11:150:
    lexical error in string/character literal at character '\n'
Failed, modules loaded: none.
I'm using OSX's TextEdit because I'm lazy, does the UTF-8 encoding have anything to do with this? How can I fix it?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Mr. Jive posted:

I hit a roadblock on my very first Haskell program:

You're missing a quote on line 11, right before FOR.

Marx Headroom
May 10, 2007

AT LAST! A show with nonono commercials!
Fallen Rib
Thanks. This is nerve-wracking.

Scaevolus
Apr 16, 2007

Chuu posted:

This code does not work for because of double's native representation that doesn't correspond well to Decimal, which are easier to gut check then explain (3.43 -> 3.43000000000001 -> 3430000000000001 * 10 -> +inf).

Valid range of double values is from 0000.1 to 99999.

I'm assuming just adding an /epsilon value and checking the remainder against it is all I need to fix this, but my brain is so fried I can't formulate it.

Any help?

I would do something like sprintf(buff, "%.8f", float) and parse the resulting string instead of manually converting a float.

Pupienus
Jul 21, 2003

I've got a problem with Visual Studio 2008. Since it seemed more of a compiler issue than a language issue, I'm trying it here first. It's in C++, and I've got some files from the professor I need to use, but it's throwing a fit at things like this:

code:
#ifndef WIN32
  gzFile gzfp;
#endif
It doesn't seem to be excluding anything in the #ifndef or #ifdef blocks, so when it sees anything related to non-windows compatibility, it shits a brick. Am I gonna have to strip all these out one at a time or is there a way to make them work properly?

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Go to Project >> Whatever Your Project is Called Properties >> Configuration Properties >> C/C++ >> Preprocessor, make sure WIN32 is part of the Preprocessor Definitions.

Pupienus
Jul 21, 2003

Thanks, that's what I needed. I managed a workaround until this point by getting the library it was looking for, but this works better.

csammis
Aug 26, 2003

Mental Institution

Mustach posted:

Go to Project >> Whatever Your Project is Called Properties >> Configuration Properties >> C/C++ >> Preprocessor, make sure WIN32 is part of the Preprocessor Definitions.

WIN32 is also defined when you include <windows.h>

csammis
Aug 26, 2003

Mental Institution
e: :pwn:

Chuu
Sep 11, 2004

Grimey Drawer
Unless I'm missing something, CppUnit doesn't really have a way to directly access the private internals of a class like JUnit does.

1. Am I wrong? If so, what's the syntax?

2. Is there a clean way to work around this, without resorting to hacks like #ifdef x #define private public, making everything virtual and subclass, etc? Can I use 'friend' for this somehow, without really making the tested class aware of the unit test class?

Chuu fucked around with this message at 06:43 on Nov 1, 2008

microwave casserole
Jul 5, 2005

my god, what are you doing
edit: Woops, I just found out that there was a specific PHP thread for this kind of question.

microwave casserole fucked around with this message at 20:40 on Nov 1, 2008

Nahrix
Mar 17, 2004

Can't afford to eat out
(Language: C) Is there a simple way to read a char array[x] -> array[last_element], where y > 0?

I just want to read a string, starting from a given index. (eg. read "ello" from "hello"). I don't want to make a for loop for this.

6174
Dec 4, 2004

Nahrix posted:

(Language: C) Is there a simple way to read a char array[x] -> array[last_element], where y > 0?
What is y?

Nahrix posted:

I just want to read a string, starting from a given index. (eg. read "ello" from "hello"). I don't want to make a for loop for this.
Why do you think a for loop is somehow inappropriate?

Also, there is a C/C++ thread for questions like this.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Nahrix posted:

(Language: C) Is there a simple way to read a char array[x] -> array[last_element], where y > 0?

I just want to read a string, starting from a given index. (eg. read "ello" from "hello"). I don't want to make a for loop for this.

If you have char buffer[] = "Hello, World!" and you want a char * to just the second word, you can use char *world = &buffer[7] or, more directly, char *world = buffer + 7.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

ShoulderDaemon posted:

If you have char buffer[] = "Hello, World!" and you want a char * to just the second word, you can use char *world = &buffer[7] or, more directly, char *world = buffer + 7.

This, and if you need a copy for some reason you can use strcpy (or memcpy and an explicit terminator if it's a non-terminal substring).

Nubile Cactus
Aug 1, 2004
I am a cactus. :)
Anyone have a quick data structure reference? I need to brush up on a few structures and the big O complexity before a technical interview.

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again
Does anyone know of a good intro tutorial online to writing programs that modify behavior of other programs? I'm talking about things like the Steam achievement manager or D2 character editors, but it wouldn't have to be that complex or even have anything to do with games. I just want to understand how people write programs that are dependent on or change the behavior of other existing programs.

ante
Apr 9, 2005

SUNSHINE AND RAINBOWS

Queef Olbermann posted:

Does anyone know of a good intro tutorial online to writing programs that modify behavior of other programs? I'm talking about things like the Steam achievement manager or D2 character editors, but it wouldn't have to be that complex or even have anything to do with games. I just want to understand how people write programs that are dependent on or change the behavior of other existing programs.

This is kinda vague, but there are a few different ways, depending upon what you're trying to do.

Google "dll injection", "hooks", and the FindWindow function.

Dll injection will let you inject code into a program so that it'll run whatever code you want.

Hooks allow you to capture the event handlers of other programs. I've never really used them, so I can't help you there.

FindWindow is just a function that'll return the handle of a window. Look in that entire section of Microsoft's documentation. You can use find child objects(such as buttons) on the form and use SendMessage to chenge text, press buttons, etc.
That's probably the easiest of the three.

baquerd
Jul 2, 2007

by FactsAreUseless
Anyone know of an open-source cron replacement with a web based GUI suitable for enterprise development? I'm just being lazy and want to extend someone's else's fleshed out framework. PHP, Java, whatever.

dagard
Mar 31, 2005

quadreb posted:

Anyone know of an open-source cron replacement with a web based GUI suitable for enterprise development? I'm just being lazy and want to extend someone's else's fleshed out framework. PHP, Java, whatever.

Webmin has a cron interface, as I recall. I've used it before to let developers see production logfiles without giving them actual logins on the servers.

baquerd
Jul 2, 2007

by FactsAreUseless

dagard posted:

Webmin has a cron interface, as I recall. I've used it before to let developers see production logfiles without giving them actual logins on the servers.

Nifty looking package, but I'm looking for something that is a replacement for, not interacts with. But thank you anyway! Think it's just time to start planning out the structure :(

sd6
Jan 14, 2008

This has all been posted before, and it will all be posted again

ante posted:

This is kinda vague, but there are a few different ways, depending upon what you're trying to do.

Alright I'll give those a look, thanks!

Adbot
ADBOT LOVES YOU

Runaway Five
Dec 31, 2007
I hate gays almost as much as I hate good posting. Also, God is good. Amen
I have a question and a half.

When you use the STL Standard Map, it is implemented as a "Binary Tree" and therefore runs in O(lg) time.

Is there a STL form of a hash table, one that would work in O(k) time and preferably have a subscript operator? Thanks in advance.

Also, is there such a thing as a hash map?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply