Trying to loop reading in two strings and an integer an amount of times based on input, and it's giving me really messed up results (in C):
[code]
int i;
int max_entry;
printf("How many inputs will be entered? ");
scanf("%d", &input_num);
char title[100][61];
char artist[100][41];
int rating[100];
printf("\nEnter the information below (String, string, single-digit number).\n");
for(i=0; i<=max_entry; i++)
{
fgets(str1[i], 61, stdin);
fgets(str2[i], 41, stdin);
scanf("%1d", &int1[i]);
}[/code]
I've tried adding in a getchar(); before/after the scanf but it never takes input correctly if I try print out the list of information later (in the following format).
[code]
for(j=0; j<=max_entry; j++)
{
printf("%s -- %s -- %d\n", str1[j], str2[j], int1[j]);
}[/code]
Any ways to fix this? Basically here's what I'm running into:
[quote] -- Tomatoes
-- 0
Potatoes
-- 5
-- 0
Apples
-- Oranges
-- 3
-- Root Beer
-- 2686359
Iced Tea
-- 4
-- 73
Enchiladas
-- Tacos
-- 4[/quote]
When it should be:
[quote]Tomatoes -- Potatoes -- 5
Apples -- Oranges -- 3
Root Beer -- Iced Tea -- 4
Enchiladas -- Tacos -- 4[/quote]
Also when I just tested this I said I wanted to input 5 entries, but it stopped the loop after entering the fourth integer.
oh , wait sorry turns out he wants my program to use forms like this
[url]http://www.gumtree.com/cgi-bin/email_poster.pl?posting_id=96383384&ziz=2216817854[/url]
to send the emails ( from auction sites )
and send to every auction.
Seems legal, he is paying quite a lot also.
How would you describe a modular entity system/framework? I'm starting a new project and what I tought of:
-DataComponent: that holds the X,Y,Z and other stuff
-LogicComponent: it's Update function is called when conditions are met, also has a list of DataComponent dependency list
-Entity: that holds the DataComponents and the LogicComponents in a List/vector
now that I have these things, the Entity should hold its ID, typeName and name too.
Is it efficient, modular and can I do just a simple loop through all the entities, the enities loop through all its LogicComponents and so on?
[QUOTE=DSG;34712074]snip[/QUOTE]fgets() leaves the trailing newline on the input. You're better off doing scanf("%s", str[i]);
[QUOTE=Octave;34713760]fgets() leaves the trailing newline on the input. You're better off doing scanf("%s", str[i]);[/QUOTE]
My teacher is requiring us to use fgets for strings...
So I tried adding the following into the mix, but I'm still having issues:
[code]void trim_n(char str[])
{
int n_position = strlen(str) - 1;
if(str[n_position] == '\n')
{
str[n_position] = '\0';
}
}[/code]
[code]for(i=0; i<=max_entry; i++)
{
fgets(str1[i], 61, stdin);
trim_n(str1[i]);
fgets(str2[i], 41, stdin);
trim_n(str2[i]);
scanf("%1d", &int1[i]);
getchar();
}[/code]
Like this, it brings back the following:
[quote] -- Tomatoes -- 0
otatoes -- 5 -- 0
pples -- Oranges -- 3
Root Beer -- Iced Tea -- 4
Enchiladas -- Tacos -- 4[/quote]
As you can see it looks messed up for the first three lines, but then it somehow starts working the correct way starting from the "Root Beer" line.
If anyone here has experience with creating a 2D game and wouldn't mind spending some time talking to me, could you add me on steam(Rombishead)? I need a bit of help.
I've been trying to figure this out for 2 hours now and have accomplished exactly nothing.
non-homework independent java project:
Basically, I have a 30x30 array of chars representing some kind of simple maze. Currently, all I've done is initialize all of them to 'E', my empty space, and proceed to draw it into a jPanel.
The real issue comes in when I want to do pathfinding. Is there some sort of simple, inefficient (but always shortest) method with which I can find a path from one given position to another, routing around 'W' (wall) spaces? Everything I've found dives into HashMaps and Adjacency Matrixes which I have very little desire to use but could possibly learn if required. Additionally, once I've found this path, how would I go about getting it back into my char array so that I can draw it?
People on this forum seem to be fond of [URL="http://www.policyalmanac.org/games/aStarTutorial.htm"]A*[/URL]. I haven't used it, but give it a shot.
I've read an unbelievable amount about A*, Dijkstra, BFS, DFS, and a few other random methods in the last couple hours.
Unfortunately, I'm no closer to understanding how to implement them. The ones with a heuristic element especially tend to use data structures that I've never even heard of before.
In android how can I get a header/footer image to stretch across the screen when viewed on a tablet?
[QUOTE=demonguard;34719979]I've read an unbelievable amount about A*, Dijkstra, BFS, DFS, and a few other random methods in the last couple hours.
Unfortunately, I'm no closer to understanding how to implement them. The ones with a heuristic element especially tend to use data structures that I've never even heard of before.[/QUOTE]
dijkstra in c++ style pseudocode:
[cpp]
struct edge {
int node;
int cost;
edge(int node, int cost) : node(node), cost(cost) { }
};
int dijkstra(int start, int finish)
{
priority_queue<edge> pq;
pq.push(edge(start, 0));
while(!pq.empty()) {
edge best = pq.top();
pq.pop();
if(best.node == finish) return best.cost;
foreach(edge next in outgoing[best.node]) {
pq.push(edge(next.node, best.cost + next.cost));
}
}
return -1;
}
[/cpp]
I got those 3 classes : Node, Action, Action1.
Action1 inherit from Action.
Action inherit from Node.
How do I pass my values from the constructor of Action1 to the constructor of Node ?
I think it's something like this :
Action::Action( int * foo ) : Node ( * foo )
Action1::Action1( int * foo ) : Action( * foo )
But I always get this error, which I don't understand at all :
No instance of constructor "Node::Node" match the argument list.
What could be the problem ?
EDIT:
I found what was wrong, thanks anyway.
[QUOTE=ichiman94;34712861]How would you describe a modular entity system/framework? I'm starting a new project and what I tought of:
-DataComponent: that holds the X,Y,Z and other stuff
-LogicComponent: it's Update function is called when conditions are met, also has a list of DataComponent dependency list
-Entity: that holds the DataComponents and the LogicComponents in a List/vector
now that I have these things, the Entity should hold its ID, typeName and name too.
Is it efficient, modular and can I do just a simple loop through all the entities, the enities loop through all its LogicComponents and so on?[/QUOTE]
Pretty much, yes. [url]http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/[/url] is a good read about component-based entities. I've divided entity components into Physics (location, size velocity), Render (sprite at physics location) and Collision components so far, for a personal project.
You'll also need to figure out how to let components communicate with each other, or get references to components that belong to the same entity (Render needs Physics, Collision needs Physics). For example, every time a component is added to an entity, all other components are notified of this new component, and they can keep a reference to it if they are interested. The message-passing functionality described in the above article is a bit of a bloated design if all you want to do is keep components as encapsulated as possible.
I'm doing some coding in AS2, trying to make a gun work here. Everything works fine except when I create the bullets they don't have unique names.
[code]bullet = _root.attachMovie("bullet", "bull", _root.getNextHighestDepth());
bulletArray.push(["bull"]);[/code]
I've tried various things, this is the base line where it's happening. Just need to make it so it will output "bull1" "bull2" etc. (Right now it's just "bull" "bull" "bull")
EDIT: Nevermind, I really need to watch my semi-colons.
Say I divide two integers, e.g. 8/13=0.615384615384615384615384...
I need to get the nth digit after the decimal point, e.g. the user enters 5 so the program would output 8.
Now i'm using C and I tried converting it using sprintf and then searching the string but it won't work for large values (e.g. n = 60000). Is there some form of maths I could do to get the number away from decimal?
This is an assignment so I don't really want code, more of an explanation of how to do it really.
[QUOTE=Gibo990;34738809]Say I divide two integers, e.g. 8/13=0.615384615384615384615384...
I need to get the nth digit after the decimal point, e.g. the user enters 5 so the program would output 8.
Now i'm using C and I tried converting it using sprintf and then searching the string but it won't work for large values (e.g. n = 60000). Is there some form of maths I could do to get the number away from decimal?
This is an assignment so I don't really want code, more of an explanation of how to do it really.[/QUOTE]
Multiply number with 10^n, floor the result, mod(10).
Though that's so obvious maybe I'm missing something. Also I doubt that'll work with 60000 because floats are assholes.
Also dividing 2 natural numbes will always give you a rational number, and thus a repeating sequence of 10 or less differing digits (Assuming it doesn't terminate). You could find out the sequence and get whatever decimal like that, too. That'd be more accurate.
In your example, the sequence is "615384", so you mod(n-1, 6)+1 the number given and just pick the number at that position (n = 60000 would be n = 6 and thus 4.)
[QUOTE=Maurice;34739897]Multiply number with 10^n, floor the result, mod(10).
Though that's so obvious maybe I'm missing something. Also I doubt that'll work with 60000 because floats are assholes.
Also dividing 2 natural numbes will always give you a rational number, and thus a repeating sequence of 10 or less differing digits (Assuming it doesn't terminate). You could find out the sequence and get whatever decimal like that, too. That'd be more accurate.
In your example, the sequence is "615384", so you mod(n-1, 6)+1 the number given and just pick the number at that position (n = 60000 would be n = 6 and thus 4.)[/QUOTE]
Ok, i've done as you said (multiply 10^n, floor & mod) but it's still not working right.
[code]
#include <stdio.h>
#include <math.h>
main()
{
int a;
int b;
int n;
double divided;
int answer;
scanf("%d %d %d", &a, &b, &n);
divided = ((double)a/(double)b);
//printf("%.52f", divided);
divided = pow(10, n)*divided;
floor(divided);
answer = (int)divided % 10;
printf("%d", answer);
}
[/code]
When I printed the divided variable the result was not the same as 0.615384615384. It was: 0.6153846153846154187760930653894320130348205566406250 which is obviously not correct. Am I not dividing the numbers correctly?
[QUOTE=Gibo990;34740135]Ok, i've done as you said (multiply 10^n, floor & mod) but it's still not working right.
When I printed the divided variable the result was not the same as 0.615384615384. It was: 0.6153846153846154187760930653894320130348205566406250 which is obviously not correct. Am I not dividing the numbers correctly?[/QUOTE]
What do you mean the divided variable wasn't correct? It's obviously not gonna be accurate because of the data type. That's why I suggested the other method.
This works for me (in relatively small n):
[lua] a = 8
b = 13
n = 5
result = math.floor(a/b * 10^n) % 10
print(result)[/lua]
outputs 8
-snip
Got it fixed.
Sorry if this is kind of a "noob" question, but I was reading through accelerated C++ and why is the first example valid and the second one isn't?
[cpp]
const std::string hello = "hello"
const std::string message = hello + ",world" + "!";
[/cpp]
[cpp]
const std::string balgh = "!"
const std::string message = "hello" + ",world" + balgh;
[/cpp]
Because "hello" is const char *, not std::string.
[editline]17th February 2012[/editline]
(Possibly even const char * const but I think that may depend on the platform)
[editline]17th February 2012[/editline]
Correction: "hello" and ",world" are. At least one of the two strings you're concatenating has to be std::string for it to work, and they're evaluated left-to-right.
[QUOTE=esalaka;34741547]Because "hello" is const char *[/QUOTE]
const char[], actually, though arrays decay into pointers.
Hey guys, probably a thick question here but thought it was worth asking you the best way to do it. I'm writing a forms application in C# for generating a few pieces of data and then manipulating a docx document and xslx file's contents. I was just wondering what the best way would be to access the data within, I know it's XML within which is a start, so is it as simple as just accessing it as xml? Any input would be great.
-snip-
how do I always end up in the wrong thread :\.
Ok so i figured out the dynamically naming bit. But i'm still having trouble, now my collision isn't picking anything up.
Where the bullet is made and put into an array:
[code]bullet = _root.attachMovie("bullet", "bull", _root.getNextHighestDepth());
bulletArray.push(["bull"+b])
b+=1[/code]
Enemy getting hit:
[code] for (i = 0; i < _root.bulletArray.length; ++i)
{
if (this.hitTest(_root.bulletArray[i]))
{
_root.bulletArray[i]._x = -1000;
_root.bulletArray[i].dead = true;
this.hp -= 5;
}
}[/code]
C#
I'm trying to delete a file with the confirmation dialog. I searched around and found that I can use Microsoft.VisualBasic.FileIO.FilesSystem. The problem is that this namespace doesn't exist for me.
Am I doing something stupid or?
Any idea whats causing these errors? SFML works fine with a console application but not when creating a window.
[IMG]http://i967.photobucket.com/albums/ae154/chrismelling/errors-1.png[/IMG]
you seem to not be linking to the right libraries
[QUOTE=Richy19;34749596]you seem to not be linking to the right libraries[/QUOTE]
Which ones do i need to link for SFML/Graphics and SFML/window?
Sorry, you need to Log In to post a reply to this thread.