156 Posted Topics
Is it possible to read a whole file at once with text files, or can I only use fgets and is that the most data I can fetch at any time? (fread() doesn't work on text files, I've experienced and then been told ;-)). Thanks in advance, PS: And suppose … | |
Re: You'd better go and code something yourself I think, or show us what you have so far. Of course, that needs to be more than the code posted above + some misc. main function. | |
How would I reuse functions in C? I've tried simply sticking them in a [icode]#include <myfunctions.h>[/icode], but that didn't work... Any (complete) suggestions/links on how to do this? I googled some and found this: [code]The way to write a header file is: functions.h: int sum( int a, int b) ; … | |
Does anyone know if it's possible to create a shellscript that knows when it's fopen()ed? So when any process fopens() it, it can take an action? Thanks in advance, | |
Re: You'll need 64-bits integers for that. Depends on your compiler (afaik) if it supports it. Look it up. If your compiler supports a bit of C99, you should be able to do: [code=c] unsigned long long int b = 8132123781237;[/code] ![]() | |
Howdy folks, Does anyone know if GCC is capable of creating a fixed length 1D array of an N-Dimensional array for reasons of speed? I've heard it matters quite a lot if one works constantly with N-Dimensional (with N != 1) compared to 1D arrays in terms of speed, but … | |
Re: It's probably the indeed that. DS: Data Segment, so it'd be.. DS + [78E32C]. I can't think of anything else, pretty sure it's that. | |
Re: To save some resources you could also try and not redraw when resizing, only when it's done resizing. No clue as of how, but I know it's possible. | |
Is it possible to put compile-time conditional code in template functions? Kinda like, [code=cpp] template <class T> void print(T &foo){ cout << foo; #if T == float cout << " is a float." << endl; #endif }[/code] Something like that, I hope I made myself clear. Thanks in Advance, | |
Hey guys, How would one create a vector of pointers to functions? I know from C to create an array of functions, but I'd like to learn how to do it with vectors as well. Here are my efforts so far: [code=cpp]#include <iostream> #include <valarray> #include <vector> #include <ctime> #include … | |
Re: Coming from C, just make n = 100. Access times is about 8 times as fast and you'll lose little memory in return.. Unless you're making a quazillion of those structures of course. | |
Re: You can use atoi() for converting "ASCII" to "integer". :) | |
Re: You're coding in C++. Forget about global variables, try and make a class that has all those variables. If you can't fit it in a class or function you're quite possibly doing something wrong. Globals are considered dangerous when you tend to use them as much as you do. It … | |
Re: That structure, &cad, has a member: sin_addr. Use inet_ntoa() to convert it to a string and print it. | |
Re: Just make it [code=c]int main(int argc, char *argv[]){[/code] It also works on MSVC++. @ iamthwee: Examples on MSDN use that, I think. | |
Re: That depends on your OS in C++. C++ itself doesn't have functions for that. Maybe some library does have crossplatform functions for it. If you're on Windows, go to MSDN and lookup the threading functions there. | |
Hi guys, I've got two loops, and I want to be able to continue; the outermost loop when the innermost loop finds something. How would I do that? [code=c] //(...) for (n = startStorage; n < quadcount; n++) { if (!notOptimized(n, optimized)) continue; int *x = &quadindex[n*4]; for (eachX = … | |
Re: I must admit I don't know 100% what you're trying to do, but as far as I know, a C-style string object _is_ a general character array. Maybe you can create a function that returns a <char *> and print that to your textbox? Make sure the memory the <char*> … | |
Re: Can't you use qsort() for this? It'd make the code a lot shorter... and easier I guess. And a, a bit more precise about the error? What are you getting? Segfaults or just a not-sorted listbox? | |
Re: *[code=c]for(t=1; t >= 4; t++){<code>} [/code] You use comma's in the for() loop when you want multiple statements, like this: [code=c] int i, j, n; for(i = j = 0, n = 5; i < 10 && j <= 20; printf("%d %d %d", i, j, n), i++, n = n … | |
Re: I think this comes down to: Does it cross this line/face. For a 3D-object you'd have to at least have a bounding box. When an other objects is IN the bounding box (easy to check) check if it hits one of the faces of your 3D object. In 2D it's … | |
Hey guys, I've written quite a large piece of code the past few days, and today I've cleaned it up a bit, divided it into functions (I know, bad, should've done it the other way around) etc. etc. The project is a simple 3D thingamadingy, the program is able to … | |
Re: What errors are you getting? Why isn't your code in code-tags? ... or indented for that matter? You should post this along with your compiler. You're trying to use cout without `#including <iostream>`. That won't work I guess. You're `#including <string>`, but then using a `<char*>` instead of a `<string>`! … | |
Re: By the way blrjohn, you could also try and fire up a console and execute your program from there. It won't disappear then. I dunno on which OS you are, but guessing it's Windows (80% market share or something eh): Go to: Start -> Run type in "cmd" Hit enter. … | |
Hi guys, Could you tell me what's wrong with this code? I don't get why the compiler says it can't find a matching function... [code=cpp]#include <iostream> #include <vector> using namespace std; template <class T> int printVector(vector<T> &x){ for(unsigned int col = 0; col < x.size(); col++){ cout << x[col] << … | |
Hi guys, I'm getting a segfault and I don't really understand why.. Here is the code n, i, quadcount, quadPerVert and quadindex are all (arrays of) unsigned integers. [code=cpp]unsigned int *quadsPerVert = new unsigned int[quadcount * 4]; //(...) vector<vector<unsigned int> > quadsPerVertIndex; quadsPerVertIndex.reserve(quadcount * 4); for (n = 0; n … | |
Re: Well it's not necessarily bad. If you are sure you are only going to recurse N-times, with N being.. say, below 2000, it's okay to do it recursive. I somewhere read: "Never hire a developer who computes the factorial using Recursion." What it says it that you should avoid recursion … | |
Hi guys, I tried rewriting my C-ish C++ function to true C++, but I'm failing so far: The first function (working) [code=cpp]const visualPart * entity::getVisualPart(unsigned int wantLOD){ for(unsigned int i = 0; i < visualEntity.size(); i++){ if(visualEntity[i]->LOD == wantLOD){ return visualEntity[i]; } } return NULL; }[/code] And the second (not … | |
Re: Use clock(), clock_t and CLOCKS_PER_SECOND. That way you can get the time in milliseconds, nanoseconds.. whatever you want. ;) | |
Hey guys, I'm parsing this WaveFront .obj file, still (for those that have read the previous post), but it has some really weird error in it that I haven't seen in a program before. The parsing algorithm starts out like this: [code]Open the file in textmode. Get filesize Allocate buffer … | |
Hey guys, An char* to string conversion looks to be generating a segfault. I'm pretty sure that's not it, but that's when GDB says it received one... Well, here's the, what I think, relevant code. If you think more code is relevant I'll post that too of course. Entity.h (objLocation … | |
Re: You're getting C++ errors. C++ is a lot stricter. Try using a C compiler. ;) | |
Is there any difference between those function declarations in C++? Since in C the first states "take any and as much arguments as you like", and the latter means take none... Thanks in Advance, Nick | |
Re: Not to be an asshole, but: [URL="http://www.justfuckinggoogleit.com/search.pl?query=C+example+program+-"C%2B%2B"+-"C%23""]click here! :D[/URL] Too bad that doesn't work, but you can figure it out. Examples are abundant on the web. | |
Hi guys, I'm having this weird error with undefined references to static variables, and was wondering what I'm doing wrong. Here's the header: World.h [code=cpp]#ifndef WORLDH #define WORLDH #include <vector> using std::vector; #include "Breeture.h" class World{ friend class Breeture; public: World(vector<Breeture*> *initialBreetures); World(unsigned int mutChance, unsigned int breetures); void NewBreeture(const … | |
Re: There are plenty of C features considering time. Read up on them. The linked list approach seems efficient enough for this task. | |
Re: Integer division will always be zero as "C" floors it. Odd number: 5 5 / 2 = 2 2 / 2 = 1 1 / 2 = 0 Even number: 4 4 / 2 = 2 2 / 2 = 1 1 / 2 = 0 As you can see … | |
Hey guys, I come over from C, wanting to learn C++. I have a nice little book but figured I could use a project to get me going. So I magicly crafted code, and ran into this problem: [icode]C:\Code\Rapture\World.h|7|error: ISO C++ forbids declaration of `Breeture' with no type|[/icode] With this … | |
Re: Shouldn't matter in what language your DLL is made, I think you need to figure out how to thread in RealBasic and call the functions from your realbasic program. | |
Hiya fellas, I just made this Knight's Tour program, and wish to speed it up without making it non-brute force. So it shouldn't have any intelligence. I did most I could, and was wondering if you guys know more ways to speed this program up. First thing I thought about … | |
Re: Are you working on Windows or Unix? I know that windows has some functions in the Win32 API for setting pixels in the console screen. | |
Hey, When quick googling didn't really clarify, I'd like to ask here. When declaring an N-dimensional array, 2D in this case, how to set them all to zero? For 1D arrays it should work with type name[n] = {0}; Is the same approach also guaranteed to work for N-Dimensional arrays … | |
Re: [url]http://msdn.microsoft.com/en-us/library/ms630343%28VS.85%29.aspx[/url] I think you should start there, but it's gonna be quite a lot of work I'm afraid. I've never done it myself, but that link seems to be good. If you are on Windows, that is. If you like examples and hadn't found it yet: [url]http://msdn.microsoft.com/en-us/library/ms630343%28VS.85%29.aspx[/url] | |
Re: Well, I tend to use them when it saves me adding numerous parameters to some functions. I think you can use global variables, but you should at least limit most of them to one source file with the static modifier (or without, since it's the default). When you write a … | |
Re: So first you open it, then you read it in, parse the file in your structure, and move on to the next. Reading in a file: fread() Parsing: Your own mix and a bit of sscanf(); writing would be exactly the opposite: sprintf() and fwrite(). sprintf and sscanf work like … | |
hai. I'm trying to compile a program split up across multiple files. The code is far from complete, but I noticed lots of compiler warnings and errors. This ought to be due to splitting the code up: I thought the preprocessor simply copy and pasted the code into main.c when … | |
|
The End.