|
xgalaxy posted:Do yourself a favor and drop the class now, if you can, and pickup some other class instead. Unfortunately, I can't just drop the class so easily. I just got admitted into upper division this semester, and this class is the only one in my major that I'm allowed to take right now - as in, all the other upper div courses require this course as a prerequisite. The only reason this particular instructor is teaching the class at all is because the guy who was supposed to teach it had to back out after being diagnosed with brain cancer (I am not making this up), and this dude was the only person the school could find to teach it at the last minute.
|
# ? Jan 28, 2013 03:04 |
|
|
# ? Jun 9, 2024 04:54 |
|
I'm trying to get a grasp on windows in the ncurses library for C, but I'm having trouble getting the wprintw() function to work correctly. The program compiles just fine, but I can't actually see any of the content I wanted printed into the window I create. Could somebody let me know where I went wrong, please?code:
|
# ? Jan 28, 2013 20:11 |
|
RationalTangle posted:I'm trying to get a grasp on windows in the ncurses library for C, but I'm having trouble getting the wprintw() function to work correctly. The program compiles just fine, but I can't actually see any of the content I wanted printed into the window I create. Could somebody let me know where I went wrong, please? I think you have to call wrefresh(my_win); IIRC, refresh only updates the default window. Edit: nevermind, you're actually doing that.
|
# ? Jan 28, 2013 20:19 |
|
I think it should just be my_win = initscr() without the newwin(0,0,0,0) call. edit; that only really applies for the exact case of the code you pasted though. ncurses is probably the shittiest library I've ever dealt with and the solution to almost every problem is to intersperse refresh(); all through your code until it works. To make your code work the way you want with any sized newwin() you can just add a refresh() call after newwin(). I have absolutely no idea why it's needed in one case but not in others, and it's probably not consistent across platforms (I know that on cygwin refresh() is needed more often, for example). The Gripper fucked around with this message at 21:47 on Jan 28, 2013 |
# ? Jan 28, 2013 21:22 |
|
That works great. Thanks!
|
# ? Jan 28, 2013 22:42 |
|
I'm having a weird problem with a function call somehow losing all but the first value of my array. In debug I can see that the array has the right values in it right before the function call, but when it gets to the other side, only the first value remains, and the array appears to be of size 1? The relevant code looks like this: code:
When it's called, the values are correct (for example the values will be 10 20 30 40 50 or 10 20 30 0 0 or whatever), but when I look at it or try to use it in the assessgrades() function, it's a single element array and the only value will be 10.
|
# ? Jan 29, 2013 15:17 |
|
WHERE MY HAT IS AT posted:I'm having a weird problem with a function call somehow losing all but the first value of my array. In debug I can see that the array has the right values in it right before the function call, but when it gets to the other side, only the first value remains, and the array appears to be of size 1? "Average =+ grades[i]" means it equals positive grades[i]. Which means you're re-setting average each loop. That should be "Average += grades[i]". If there's no error, you're then also calling assessGrades again but with average as the parameter, which is a double, yet assessGrades takes a 5 long int array. Where you have assessGrades(average) you should be returning average, so replace that with "return average". You'd also have to replace "void assessGrades" with "double assessGrades". To run it you'd have to output the return value, so "cout << assessGrades(grades) << endl;" should work.
|
# ? Jan 29, 2013 15:38 |
|
Err, yeah. I've changed that part, thank you. Regardless, I'm only getting one value in my array. The second call at the bottom is working fine (it's an overloaded function). The function I posted though is being called from my input parsing function here: code:
Edit: nevermind, apparently they're there, visual studio just isn't showing them, as it's working after that change. You're brilliant, thanks! WHERE MY HAT IS AT fucked around with this message at 15:51 on Jan 29, 2013 |
# ? Jan 29, 2013 15:46 |
|
I think it's because Visual Studio isn't smart enough to know how long the array is after you pass it into a function. Showing the first entry is pretty safe because a zero length array would be kind of useless, but it doesn't know how many to show after that. Since you know how long the array is, you can put in "grades,5" into the watch window and it'll show you 5 entries. Also, I don't think the "5" in your first line actually does anything (except freak me out).
|
# ? Jan 29, 2013 16:05 |
|
I'm working on a program in C that prints out a string if a number is bigger than another number by 0.1 or smaller than that same number by 0.1 and I'm not entirely sure how to go about putting that together into an if statement. I know how to put in greater than or equal to/less than or equal to but doing it by a specific number is stumping me. How would I pull this off?
|
# ? Jan 30, 2013 23:12 |
|
Zeether posted:I'm working on a program in C that prints out a string if a number is bigger than another number by 0.1 or smaller than that same number by 0.1 and I'm not entirely sure how to go about putting that together into an if statement. I know how to put in greater than or equal to/less than or equal to but doing it by a specific number is stumping me. How would I pull this off? You could do: if(A - 0.1 >= B || A + 0.1 <= B) or if(fabs(A - B) >= 0.1)
|
# ? Jan 30, 2013 23:17 |
Zeether posted:I'm working on a program in C that prints out a string if a number is bigger than another number by 0.1 or smaller than that same number by 0.1 and I'm not entirely sure how to go about putting that together into an if statement. I know how to put in greater than or equal to/less than or equal to but doing it by a specific number is stumping me. How would I pull this off? In other words, if the absolute difference of the numbers is greater than 0.1. if (fabs(a-b) > 0.1) { /*code*/ }
|
|
# ? Jan 30, 2013 23:18 |
|
Alright I'm trying to make a bit of c code that would calculate gravitational potential at points on some pre-defined grid. My c is pretty rusty at this point so I'm a bit stuck on how the gently caress I store my poo poo in an array.code:
Actual problems I'm getting:
|
# ? Jan 30, 2013 23:53 |
|
Quick responses: float phitot[100][2]; declares a 100 x 2 array. It looks like you want a 100 x 100 x 2 array. That would be float phi tot[100][100][2];. You cannot assign multiple array elements at once like that. You need two assignments: C++ code:
C++ code:
I do not know why your compiler is complaining about phix and phiy being unused.
|
# ? Jan 31, 2013 00:09 |
Your array with dimensions [100][2] means an array with two elements, which each is another array of 100 elements, which are floats. That means you have 100*2=200 elements total. Meanwhile, you are calculating values at 100*100=10000 different coordinate pairs. You also have two values calculated per coordinate pair, so 20000 total. That won't fit into your array at all. For the assignment into the array, this line: C++ code:
Second, your index into the second dimension of the array has the same problem, range, but would also hit the problem that your second array dimension is declared to be of length 2. So fix those array dimensions. Second, after the equals sign, that's invalid syntax. You want to store two values into the array. Either you need to make two stores (into two different indexes), which is what you would do if you have an array of floats as it is now, or you should make a struct to hold your value pairs. But [a][b] has no meaning in C, except when used to index an array which you aren't doing there. It's not an expression by itself. Lastly, your function is declared as returning a float, but in your return statement you are returning an array of floats. If you want to return an array from a function you have two options: Either have the caller allocate the array for you, and then pass in a pointer to the allocated memory, or have the callee allocate the memory and return a pointer to that. The former allows the caller to make a static or stack allocation, while the latter requires you to make a dynamic allocation. Also see what rjmccall wrote above.
|
|
# ? Jan 31, 2013 00:13 |
|
Okay cool. I somewhere knew about indexes starting at 0 and doing it anyway . Trying out the rest, still getting hung up on that bizarre not recognizing variables I have right loving there. Trying a different compiler in a bit and seeing if that bit is just gcc being weird.
|
# ? Jan 31, 2013 01:53 |
Shugojin posted:Okay cool. I somewhere knew about indexes starting at 0 and doing it anyway . Did you fix the completely broken assignment syntax? Because I can imagine the compiler might throw up when presented with that.
|
|
# ? Jan 31, 2013 02:04 |
|
The compiler has figured out that I did in fact use phix and phiy now, at any rate, but I'm now all confused as to how I declare and pass the pointer I am attempting to declare the pointer like this, which seems to be used in all the literature I've looked at. code:
code:
code:
'function' : cannot convert from 'float' to 'float *(*)[100][2] and giving me a warning about 'Potential' : different types for formal and actual parameter 4 (Also some warnings where I would possibly lose data by converting to type int, but this is more specifically an astrophysics problem so truncating things is going to be a negligible error )
|
# ? Jan 31, 2013 03:08 |
|
Shugojin posted:
If you want phipass to be a pointer to phi[0][0][0], the syntax is phipass = &phi[0][0][0]; (the ampersand can read out loud as "the address of") Edit: Ignore most of what I wrote below, it is stupid and wrong, I was asleep at the time. But phipass is still redundant. But you don't want phipass to be a pointer to phi[0][0][0], or a pointer to a float at all, you want it to be a pointer to a pointer to a pointer to a float, like phi, so you actually would want to declare it as float ***phipass. And then phipass = phi; Which means phipass is completely redundant, you could just pass phi to your function as a float***. Edit: fip-rear end. roomforthetuna fucked around with this message at 19:56 on Jan 31, 2013 |
# ? Jan 31, 2013 03:50 |
|
I'm involved in a project that requires targeting Android and x86 Windows. The application would need OpenGL support with shaders and multitouch functionality. Other niceties (like GUI widgets) would also be nice. Does such a pipe-dream of a framework exist?
|
# ? Jan 31, 2013 03:59 |
|
roomforthetuna posted:But you don't want phipass to be a pointer to phi[0][0][0], or a pointer to a float at all, you want it to be a pointer to a pointer to a pointer to a float, like phi, so you actually would want to declare it as float ***phipass. That's not what arrays are in C or C++ and that will not compile. Arrays are not pointers. For convenience, the language gives an array the equivalent of an implicit conversion to a pointer to its first element (think of it like a type with an overloaded implicit conversion operator). A multidimensional array is an array of arrays, meaning that a pointer to the first element is a pointer to an array type. float phi[100][100][2] would decay to a float (*)[100][2]. It will not ever be able to be converted to a pointer to a pointer, since multidimensional arrays are a single chunk of contiguous memory, with no pointers in their representation (the pointer you get from decay is just a temporary).
|
# ? Jan 31, 2013 04:09 |
|
roomforthetuna posted:If you read those asterisks and their phipasses out loud, the first line says "a pointer, phipass" and the second line says "the contents of phipass". Oh god stop, that is not how arrays in C work, please do not repeat this. Shugojin: all you need to do is this: C++ code:
An expression of array type always (with one major exception, below) immediately "decays" by becoming a pointer to the first element: one level of array turns into one level of pointer. So the expression phi has type float(*)[100][2]. An analogous thing happens with function parameters: if the parameter is written with an array type, it's really treated as a pointer to the element type: thus, Phitot really has type float(*)[100][2]. So the types match up and it works. Note that the outermost (first) bound of the array type is completely ignored in the type-checking here. Okay, about that exception: if you take the address of an array, it doesn't lose that level of array-ness. So the expression &phi would have type float (*)[100][100][2]. If you wanted, you could declare Phitot as float (*Phitot)[100][100][2], and pass &phi as the argument; that would also work, and behind the scenes exactly the same thing would happen, with one very big exception: expressions like Phitot[x] would be indexing into an array of float[100][100][2]s, not an array of float[100][2]s. That's not what you want, because Phitot[3] would be way past the end of your array, so you'd end up having to write (*Phitot)[x] everywhere and it'd be a huge pain in the rear end. While I'm at it, I should explain subscripting. Subscripting in C works via pointer arithmetic, so you can subscript basically any pointer. So when you write something like phi[x], first phi decays into a float(*)[100][2], then you add x to it (skipping past x float[100][2]s), and then you get an l-value to whatever you're now pointing at. Since that's an array, if you now subscript again (phi[x][y], it'll decay to a float(*)[2], you'll skip past y float[2]s and end up with an l-value at that. You can then subscript *again* and you'll be skipping past floats, and you'll end up with an l-value to a float, which you can read a single float out of or write a float into or whatever you please.
|
# ? Jan 31, 2013 04:33 |
|
That Turkey Story posted:That's not what arrays are in C or C++ and that will not compile. Arrays are not pointers.
|
# ? Jan 31, 2013 07:05 |
|
I've somehow told Visual Studio 2010 that it shouldn't launch my application when I click F5 or CTRL+F5. It creates a .exe-file, but it doesn't try to launch it and the files works fine. What have I messed up?
|
# ? Jan 31, 2013 19:09 |
|
e: never mind I'm an idiot
raminasi fucked around with this message at 00:23 on Feb 1, 2013 |
# ? Feb 1, 2013 00:16 |
|
Boz0r posted:I've somehow told Visual Studio 2010 that it shouldn't launch my application when I click F5 or CTRL+F5. It creates a .exe-file, but it doesn't try to launch it and the files works fine. What have I messed up?
|
# ? Feb 1, 2013 05:36 |
|
STL-style containers from Google using B-Trees. Apparently they offer much better performance than std::map and std::set for large numbers of elements.. http://google-opensource.blogspot.ca/2013/01/c-containers-that-save-memory-and-time.html
|
# ? Feb 2, 2013 16:10 |
|
I'm trying to write a programme that will calculate the area and circumference of a circle based on the radius, seems easy enough right? For whatever reason, I can't get it to compile on the UNIX server for the life of me and I can't figure out why.code:
code:
|
# ? Feb 4, 2013 08:56 |
|
Well you're not giving it any value to use in the format string in place of %d, so you'd want something like:code:
|
# ? Feb 4, 2013 09:00 |
|
The Gripper posted:Well you're not giving it any value to use in the format string in place of %d, so you'd want something like: God dammit I thought that didn't look right, cheers mate. Edit: it finally compiled after I removed the usage of %d twice in the same printf FAT32 SHAMER fucked around with this message at 09:17 on Feb 4, 2013 |
# ? Feb 4, 2013 09:05 |
|
Tusen Takk posted:
Also, this is just the formula for circumference after some algebraic manipulation. (C does not have a built in power operator.)
|
# ? Feb 4, 2013 09:14 |
|
rjmccall posted:Also, this is just the formula for circumference after some algebraic manipulation. (C does not have a built in power operator.) Good catch on that I thought I had used the carot not the asterisk for some reason.
|
# ? Feb 4, 2013 09:19 |
|
Tusen Takk posted:Good catch on that I thought I had used the carot not the asterisk for some reason. Like the man said, c++ has no built in power operator. The carat (^) will compute bitwise XOR, not exponentiation.
|
# ? Feb 4, 2013 09:23 |
|
Tusen Takk posted:God dammit I thought that didn't look right, cheers mate.
|
# ? Feb 4, 2013 09:29 |
|
FamDav posted:Like the man said, c++ has no built in power operator. The carat (^) will compute bitwise XOR, not exponentiation. Right, I replaced it with r*r. code:
edit: ignore all the comments, it's part of the assignment
|
# ? Feb 4, 2013 09:43 |
Unless you mean "class" as in school class, you don't have any classes in that program, just to be pedantic. (You have a single free standing function.) I would also suggest putting comments of that length on a separate line before the one it explains. And while that kind of in-depth comments can be good while learning, it's not something you would use in a real program. Comments should explain why, not what. (Yes I'm going to only talk about those comments you told us to ignore!)
|
|
# ? Feb 4, 2013 09:53 |
|
shodanjr_gr posted:I'm involved in a project that requires targeting Android and x86 Windows. The application would need OpenGL support with shaders and multitouch functionality. Other niceties (like GUI widgets) would also be nice. MoSync seems to at least be an attempt at what you're describing.
|
# ? Feb 4, 2013 10:43 |
|
How do people do GUI Windows programming in C++ nowadays? Is there a favored framework, or is it a mix of MFC, ATL, QT, etc?
|
# ? Feb 4, 2013 13:36 |
|
tractor fanatic posted:How do people do GUI Windows programming in C++ nowadays? Is there a favored framework, or is it a mix of MFC, ATL, QT, etc? It all still stinks. Sorry, I don't actually have a recommendation, I just felt the need to say that.
|
# ? Feb 4, 2013 14:17 |
|
|
# ? Jun 9, 2024 04:54 |
|
Qt is probably the least bad choice.
|
# ? Feb 4, 2013 14:59 |