• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=Relaxation;38622053]In C, can someone please give an example, or link me to a resource / tutorial over reading a file and storing the items into a linked list? I literally can find nothing conclusive on it when I google it, It's all people with some botched code asking for help. Please someone help me D:[/QUOTE] It's not precisely what you're after, but [url=http://pastebin.com/FWr85rfW]this[/url] should give you a start. It was an assignment I did this semester - read a string in from the terminal, put each character into a linked list; loop through the list and print each character out; loop through the list and remove all vowels; print the list out again. The highlighted section is where I'm reading user input from the terminal, and so that's more or less where you'd change the code to read from a file in your case.
I need something to simulate the amount of light there is outside. And I have to do it in PHP. I have to change the value in a database every 10 minutes and then look in the database what the value is to make a graph. Now I've got the graph and stuff done already, but changing values based upon the time seems tedious and requires alot of code. So I'm wondering if there is an easy way of doing this. (I don't really know what the max and minimal values are between bright daylight and dim moonlight, so just pick something random)
As part of an assignment I have to check over some java code that the lecturer has created, the class he gives us extends Dictionary and implements Cloneable The problem is that it has 2 methods that prevent it from compiling, thats what we have to do identify and fix problems in the code the problem is I dont know how to fix it: [cpp] public Enumeration elements() { return new ArrayEnumeration(values,nelems) ; } [/cpp] [cpp] public Enumeration keys() { return new ArrayEnumeration(keys,nelems) ; } [/cpp] The problem is this ArrayEnumerator class is part of apache collections, and either way its deprecated. Does anyone know how it can be fixed? what I want to do is return an enumerator to the key array or to the value array but its not letting me do so.
How do I make case sensitive sql queries?
In C#, i have this: [code] string s = "1000"; double mapCoordsDouble; if (double.TryParse(s, out mapCoordsDouble)) { //etc... } else { Console.WriteLine(s + " is invalid"); } [/code] 's' is obviously a number but still, "1000 is invalid" gets printed. Why is this?
[QUOTE=Funley;38627104]In C#, i have this: [code] string s = "1000"; double mapCoordsDouble; if (double.TryParse(s, out mapCoordsDouble)) { //etc... } else { Console.WriteLine(s + " is invalid"); } [/code] 's' is obviously a number but still, "1000 is invalid" gets printed. Why is this?[/QUOTE] That should work: [img]http://www.fearswe.net/s/Capture-201211281924308063-1183x256.png[/img] Try adding .0 to 1000 and see if it changes anything. Or do the regular double.Parse and see what the exception is.
[QUOTE=Lord Fear;38627325]That should work: [img]http://www.fearswe.net/s/Capture-201211281924308063-1183x256.png[/img] Try adding .0 to 1000 and see if it changes anything. Or do the regular double.Parse and see what the exception is.[/QUOTE] The whole double.TryParse thing is just to check if 's' is a number so double.Parse is kinda clunky to use in checking if 's' is only numbers.
[QUOTE=Funley;38627406]The whole double.TryParse thing is just to check if 's' is a number so double.Parse is kinda clunky to use in checking if 's' is only numbers.[/QUOTE] I know the differences. I'm telling you to try it instead because it will cast an exception containing some form of error if it can't parse it instead of just returning false. It wasn't a suggestion to use it instead in the end, more of a way to get more information on why it's not working since it should.
[QUOTE=Lord Fear;38627428]I know the differences. I'm telling you to try it instead because it will cast an exception containing some form of error if it can't parse it instead of just returning false. It wasn't a suggestion to use it instead in the end, more of a way to get more information on why it's not working since it should.[/QUOTE] Well, double.Parse works perfectly. No errors raised. What.
[QUOTE=Funley;38627453]Well, double.Parse works perfectly. No errors raised. What.[/QUOTE] That's weird. Because it really should work the same. And it is a valid number, why the TryParse doesn't work I can't say. Try cleaning the solution and do a full rebuild. Can even try restarting VS.
[QUOTE=Lord Fear;38627570]That's weird. Because it really should work the same. And it is a valid number, why the TryParse doesn't work I can't say. Try cleaning the solution and do a full rebuild. Can even try restarting VS.[/QUOTE] I don't actually care since the .Parse way is working perfectly fine now.
[QUOTE=Funley;38628393]I don't actually care since the .Parse way is working perfectly fine now.[/QUOTE] Parse sucks though, you might have found a bug in the .NET framework so it would be helpful if you cared. Obviously I can't force you, but it would be nice to find out what the issue really is.
[QUOTE=gparent;38629311]Parse sucks though, you might have found a bug in the .NET framework so it would be helpful if you cared. Obviously I can't force you, but it would be nice to find out what the issue really is.[/QUOTE] Kind of hard since .Parse works perfectly with no errors while .TryParse returns false from the same string.
[QUOTE=Funley;38628393]I don't actually care since the .Parse way is working perfectly fine now.[/QUOTE] As long as you're 100% sure there will never be an invalid number then I guess there shouldn't be any problems. But if you're working with userinput then you'd have to get some unneeded exception handling for using the .Parse
[QUOTE=mechanarchy;38623578]It's not precisely what you're after, but [url=http://pastebin.com/FWr85rfW]this[/url] should give you a start. It was an assignment I did this semester - read a string in from the terminal, put each character into a linked list; loop through the list and print each character out; loop through the list and remove all vowels; print the list out again. The highlighted section is where I'm reading user input from the terminal, and so that's more or less where you'd change the code to read from a file in your case.[/QUOTE] Ok, I got that function figured out, but now I need help with printing it out. Here's the function I MUST use: [code] void PrintItemTable ( FILE *fpout, /* FILE stream to print to (set to stdout for screen) */ item_t *itb /* list of items to dump to screen */ ) { /* declarations here! */ fprintf(fpout, " NUM NAME DAMAGE COST WEIGHT\n"); fprintf(fpout, "==== =============================== ====== ============ ========\n"); /* print all the lines */ printf("\n"); while ((itb != NULL) && (itb->name != NULL)) { } } [/code] The while statement at the end is what I added, and inside the while loop is where I'm spose to make it print the thing's that I stored into the linked list in my first function. The specific code I used to store stuff into the linked list is this: [code] while( fscanf( fp, "%s %i %f %f", buf, &(current->dam), &(current->cost), &(current->weight)) != EOF ) { struct items *new = malloc( sizeof(struct items) ); current->next = new; strncpy(current->name,buf,32); current = new; } [/code] So what do I add inside the while loop to make it print? *Note, not looking for a straight answer persay, sudo code or even some basic / generic input can help! Thanks!
[QUOTE=Relaxation;38629762]So what do I add inside the while loop to make it print? *Note, not looking for a straight answer persay, sudo code or even some basic / generic input can help! Thanks![/QUOTE] To print it out, try combining this function [code] fprintf(fpout, " NUM NAME DAMAGE COST WEIGHT\n"); [/code] With the syntax and arguments you use in [code] fscanf( fp, "%s %i %f %f", buf, &(current->dam), &(current->cost), &(current->weight)) [/code] You'll need to change a couple of things, but you pretty much just merge those two and you have your answer to printing out all the details of an entry. [editline]29th November 2012[/editline] Most notably you'll need to change the padding width. Look up fprintf on Google and see what the reference on it says.
Does anyone here know what kind of shadow rendering technique Dota 2 uses ? It looks like shadow mapping, but the shadows are fucking smooth. Do they blur the shadowmap after rendering? I know nobody can know for sure (unless decompile..) but maybe someone has a better guess than me.
[QUOTE=mechanarchy;38630461]To print it out, try combining this function [code] fprintf(fpout, " NUM NAME DAMAGE COST WEIGHT\n"); [/code] With the syntax and arguments you use in [code] fscanf( fp, "%s %i %f %f", buf, &(current->dam), &(current->cost), &(current->weight)) [/code] You'll need to change a couple of things, but you pretty much just merge those two and you have your answer to printing out all the details of an entry. [editline]29th November 2012[/editline] Most notably you'll need to change the padding width. Look up fprintf on Google and see what the reference on it says.[/QUOTE] when reading this (first line from tester file): [code] 'sharp tool' 4 0.5 1.1 [/code] using this code to print it out: [code] fprintf( stdout, "%s %i %f %f", (itb->name), (itb->dam), (itb->cost), (itb->weight)); [/code] I get this as the result: [code] 'sharp 0 0.000000 0.000000 [/code] So 2 problems here. fscanf only gets the first word in the string. Second problem is all the values are zero. Please Halp.
Scanf can't know how many spaces your name variable should contain. The pattern you provided - "%s %i %f %f" - delimits variables with whitespace. The first word will be assigned to the first variable, the second word to the second variable, and so on. Since the second word is not a number, parsing it as an integer doesn't actually do anything, so the parsing gets stuck on the second word. Possible solutions include: Make sure your name variables only consist of single words. Replace spaces in the name variable with underscores or something. Prepend a "word count" variable on each line, which corresponds to the amount of words in the name variable. Use more advanced parsing.
Looks like I need more advance parsing, considering the max character limit (set by the struct is 32 characters) with no limitations on how many space can within the 32 characters. That means I need to fix the reading / storing function (that I spent hours on :( ......) With something more... proficient? So then, how do I properly read and store given the aforementioned. Current code that needs fixed then: [code] while( fscanf( fp, "%s %i %f %f", buf, &(current->dam), &(current->cost), &(current->weight)) != EOF ) { struct items *new = malloc( sizeof(struct items) ); current->next = new; strncpy(current->name,buf,32); current = new; } [/code]
I think the easiest way for you to do it would be to replace spaces with another character. Choose something that's not likely to be used, such as ~ or ` or } etc. Then, before you save the name, make a copy and iterate through it, replacing all spaces with your selected character. When you read it back in, you read the string verbatim (which will be fine- there are no spaces for fscanf to stop on) and then before you copy the string into the struct you loop through it again and replace the other way.
What would be the best way to implement a city generator on an isometric grid?
[QUOTE=chaoselite;38633967]What would be the best way to implement a city generator on an isometric grid?[/QUOTE] The same way you would on a square grid? You just draw it from an isometric perspective? I'm not sure I understand your question. If you were asking how to generate a city in and of itself, I'd strongly recommend reading through [url=http://www.introversion.co.uk/subversion/]Introversion's Subversion dev blog[/url]. It might take you a while to get through it but I think it's worth it.
[QUOTE=Funley;38629376]Kind of hard since .Parse works perfectly with no errors while .TryParse returns false from the same string.[/QUOTE] Well .NET has source code available for these functions I think, you could probably just step through with a debugger.
So, I have array of unknown site, uninitialized. I don't know, how to add arrays of same type and fixed site to it :s. C# code: [code] VertexPositionTexture[] array; //this is the array VertexPositionTexture[] somethingToBeAdded= new VertexPositionTexture[6]; //this array needs to be added to the array, this will happen atleast 1000x [/code] Any suggestions? I need really efficient solution, so no Lists or containers here.
[QUOTE=mechanarchy;38632790]I think the easiest way for you to do it would be to replace spaces with another character. Choose something that's not likely to be used, such as ~ or ` or } etc. Then, before you save the name, make a copy and iterate through it, replacing all spaces with your selected character. When you read it back in, you read the string verbatim (which will be fine- there are no spaces for fscanf to stop on) and then before you copy the string into the struct you loop through it again and replace the other way.[/QUOTE] No it HAS to read spaces. The tester file was given by the prof. Can't I just change the parsing method in my while loop to fgets, and the body of the while loop would still be correct.. for the most part?
[QUOTE=HeatPipe;38636675]So, I have array of unknown site, uninitialized. I don't know, how to add arrays of same type and fixed site to it :s. C# code: [code] VertexPositionTexture[] array; //this is the array VertexPositionTexture[] somethingToBeAdded= new VertexPositionTexture[6]; //this array needs to be added to the array, this will happen atleast 1000x [/code] Any suggestions? I need really efficient solution, so no Lists or containers here.[/QUOTE] There are a few ways you can do this in C#, I've found that the fastest one is Buffer.BlockCopy(somethingToBeAdded, 0, array, arrayOffset, 6 * sizeof(VertexPositionTexture)); Values are in BYTES, not in indices. There's also Array.Copy, which takes its parameters as indices and is a bit slower than Buffer.BlockCopy.
[QUOTE=mechanarchy;38634210]The same way you would on a square grid? You just draw it from an isometric perspective? I'm not sure I understand your question. If you were asking how to generate a city in and of itself, I'd strongly recommend reading through [url=http://www.introversion.co.uk/subversion/]Introversion's Subversion dev blog[/url]. It might take you a while to get through it but I think it's worth it.[/QUOTE] How do you generate a city onto a 2d grid then? I went to the link and while it does have some good tips for 3d city generation, it really isn't geared toward 2d grid city generation.
[QUOTE=chaoselite;38641038]How do you generate a city onto a 2d grid then? I went to the link and while it does have some good tips for 3d city generation, it really isn't geared toward 2d grid city generation.[/QUOTE] The thing about cities is they basically are 2D - once you've got the floor level they rarely change as they go up, their cross-section stays the same. I haven't generated any cities myself, so I can't really help you much. [url=https://dl.dropbox.com/u/6929441/screenshots/citygen.gif]This animation[/url] ([url=https://dl.dropbox.com/u/6929441/screenshots/citygen-1.png]end result[/url], [url=https://dl.dropbox.com/u/6929441/screenshots/citygen-2.png]3d render[/url]) was posted in one of the WAYWO threads a few iterations back, so maybe it will give you a pointer in the right direction
Ok so when I use this: [code] FILE *fp; fp = fopen( file, "r"); struct items *root; /* Unchanging first node */ root = malloc( sizeof(struct items) ); struct items *current = root; /*char *name = malloc( sizeof(char) * 64 );*/ char name[32]; while( fgets( name, sizeof name, fp ) != NULL ) { /*fscanf( fp, "%s %i %f %f", name, &(current->dam), &(current->cost), &(current->weight));*/ struct items *new = malloc( sizeof(struct items) ); current->next = new; strncpy(current->name,name,32); current = new; } [/code] and print it out, I get this: [code] 'sharp tool' 4 0.5 1.1 0 0.000000 0.000000 [/code] This is the file I'm reading from" [code] 'sharp tool' 4 0.5 1.1 'rustysword' 8 5.0 8.1 'sword' 10 10.0 8.0 'finesword' 12 100.0 7.2 'twohanded sword' 20 200.0 15.0 [/code] Help please?
Sorry, you need to Log In to post a reply to this thread.