• What do you need help with? Version 5
    5,752 replies, posted
[QUOTE=A big fat ass;39261952]I'm having some issues with my Visual Basic Hitman Absolution disguise replacer. It's crashing for everybody with an error, but it doesn't crash for me or one of my friends. I've had 2 or 3 people testing the program as I was making it, and the older versions has worked for them up until this latest one. The thing is, I have absolutely no idea what has changed about it that is crashing for everybody except me and my friend. Here's the .exe. I downloaded it myself and it works fine, but it produces an error immediately on launch for others. [url]http://filesmelt.com/dl/Hitman_Absolution_Disguise_Replacer.zip[/url] I don't like asking to fix it, but I just have absolutely no idea what's causing it or where to start. The program works by asking you for your Hitman: Absolution folder, you pick it, then it finds out where the disguise files are and backs them up, then you can replace disguises from two lists. Here's the very sloppy source: [url]http://pastebin.com/ePbS6LVc[/url] This is the error someone reported. I can't replicate it.[/QUOTE] Try putting your I/O stuff in Try Catch blocks, checking null values when there's a possibility you may have one (If var IsNot Nothing Then in VB.NET), and please consider using C# as VB.NET makes my eyes bleed. A few other things you should look at: arrays and dictionaries.
[QUOTE=MakeR;39265093][code]matthew@Matthew-Ubuntu:~/Documents/C++$ g++ -o lua_test lua_insert.cpp -llua5.1 matthew@Matthew-Ubuntu:~/Documents/C++$ ./lua_test `stack top' 2.5 true 10 lua_insert(-3) 2.5 true `stack top' 10 [/code] lua_insert shifts the stack up including the element at n.[/QUOTE] Sweet, thanks!
Hey, got a problemn, probably more math related, but this is the most-suitable place (I think).. Im currently developing a MAPF (Multi-agent-potential-field) based nav system for a tower-defence / pseudo-rts game that me an some freinds are working on as our end our 2 year project. Im fine on the theory, and am happy making all sorts of radius-based fields i.e fields that take a distance (r) from the attractor/repulsor: [CODE] where; {k1, k2, c1, c2, a, MSD, MDR} ∈ ℝ⁺ P(d) = { k₁d, a ∈ |0, MSD-a| c1-d, a ∈ |MSD-a, MSD| c2-k₂d, a ∈ |MSD, MDR MSD : 'maximum shoot distance', MDR : 'minimum detection range', a : 'width of optimum potential ring' [/CODE] However now i need a, for lack of better words, "half conic" shaped field, that is a plane with a depressed, bisected cone of length d. Given a : position of vertex of the depressed cone. b : position of a unit i need a function to generate potentials, (scalar) of about -30 in the centre of the depression, fading to 0 away from the centre and stopping at length d. The closest i've got is given that a = (0,0) and b = (x,y) [CODE] (-0.25(|x|² + |y|²)^0.05) / √(arccos( x / √(|x|² + |y|²)) [/CODE] Which gives; [IMG]http://sphotos-c.ak.fbcdn.net/hphotos-ak-ash4/305082_549564175063099_336662453_n.jpg[/IMG] [IMG]http://sphotos-c.ak.fbcdn.net/hphotos-ak-snc7/395438_549688398384010_1134667701_n.jpg[/IMG] which is fine, but it needs to not extend right down into a pit of asymtotic-doom, needs some sort of (smooth) limmiting factor. Any solutions, advice or nudges in the right direction greatly appreciated! [editline]19th January 2013[/editline] p.s. UI mockup [IMG]http://sphotos-e.ak.fbcdn.net/hphotos-ak-ash4/293694_542211392465044_634287935_n.jpg[/IMG] > my guess was use the arc-length between b and global x axis (0,1) in a circule of radius |b| as one of the variables and distance from A ( |B-A| ) as another...somin like -100 / arclength * sqrt ( distance ) or whatever, but im guessing
I have no idea why my calculator won't work. I'm COMPLETELY new to coding, so obviously I'm missing something important, but this book claims it should work EXACTLY like in the book. Since the information would be useful later on, and experience always helps, it's disheartening to find out that a simple addition and subtraction calculation tool fails for no apparent reason. Now I know it's not cool to just hand someone your entire code and go "TELL ME WHAT'S WRONG", but for something relatively small, I feel like it couldn't hurt to ask. Anyone know why it simply will not calculate? [cpp]using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace CalculatorCalculatorGiveMeTheAliigator { public partial class CalculatorForm : Form { int firstNum = 0; int result = 0; bool addButtonFlag = false; bool subtractButtonFlag = false; public CalculatorForm() { InitializeComponent(); } private void Number1Button_Click(object sender, EventArgs e) { NumberLabel.Text += "1"; } private void Number2Button_Click(object sender, EventArgs e) { NumberLabel.Text += "2"; } private void Number3Button_Click(object sender, EventArgs e) { NumberLabel.Text += "3"; } private void Number4Button_Click(object sender, EventArgs e) { NumberLabel.Text += "4"; } private void Number5Button_Click(object sender, EventArgs e) { NumberLabel.Text += "5"; } private void Number6Button_Click(object sender, EventArgs e) { NumberLabel.Text += "6"; } private void Number7Button_Click(object sender, EventArgs e) { NumberLabel.Text += "7"; } private void Number8Button_Click(object sender, EventArgs e) { NumberLabel.Text += "8"; } private void Number9Button_Click(object sender, EventArgs e) { NumberLabel.Text += "9"; } private void Number0Button_Click(object sender, EventArgs e) { NumberLabel.Text += "0"; } private void ClearButton_Click(object sender, EventArgs e) { NumberLabel.Text = ""; result = 0; firstNum = 0; NumberLabel.Text = ""; addButtonFlag = false; subtractButtonFlag = false; } private void AddButton_Click(object sender, EventArgs e) { if (NumberLabel.Text != "") { firstNum = int.Parse(NumberLabel.Text); NumberLabel.Text = ""; addButtonFlag = true; } else { MessageBox.Show("You must enter a number!"); } } private void SubtractButton_Click(object sender, EventArgs e) { if (NumberLabel.Text != "") { firstNum = int.Parse(NumberLabel.Text); NumberLabel.Text = ""; subtractButtonFlag = true; } else { MessageBox.Show("You must enter a wumbus!"); } } private void EqualButton_Click(object sender, EventArgs e) { if (NumberLabel.Text != "") ; { int secondNum = int.Parse(NumberLabel.Text); if (addButtonFlag == true) { result = firstNum + secondNum; } else if (subtractButtonFlag == true) { result = firstNum - secondNum; } } } } } //NANANANANANANANANA //NANANNANANANANANANA //CAT MAN //NANANANANANANANANANA //NANANANANANANANANANA //MATT MAN //BA GOOM DOOSH SCHPLANG[/cpp] The program looks like [img]http://puu.sh/1Pu89[/img] and whenever I press "Equals", it resets and does not output an answer. Help? And again, sorry for asking such a "nooby" question.
[QUOTE=NateDude;39272600][cpp] private void EqualButton_Click(object sender, EventArgs e) { if (NumberLabel.Text != "") ; // Delete this semicolon. { int secondNum = int.Parse(NumberLabel.Text); if (addButtonFlag == true) { result = firstNum + secondNum; } else if (subtractButtonFlag == true) { result = firstNum - secondNum; } } } [/cpp][/QUOTE] You've got a semicolon after the condition in the if statement. Also, you aren't outputting the result anywhere; you're just giving the variable a different value. P.S. Use [noparse][cpp][/cpp][/noparse] tags.
Just a suggestion, and by no means an insult to your intelligence, as your new, why don't you try a command-line based calculator to begin with, then move on to working with forms? It helps to get a much better understanding of the logic behind programs, even before youve written anything more complicated than hello world. sit down, and think through your whole approach to the problemn, try a flow chart or other way of visualising the proscesses that happen when the program is executed. That way, once you really have a grasp of the fundamental techniques involved in sucessful programming, your (almost) language independant, the techniques are much the same..just a different syntax. I helped out with a course teaching programming in PASCAL to first-years this year, and i could easily get some of the help-documentation and tasks if you'd like, alternativly if your interested in maths aswell i STRONGLY reccomend project euler tasks : [URL]http://projecteuler.net/problems[/URL]. These have rather a steep learning curve but all require the use of fundamental statements and will help develop your technique and knolwedge of iteration, selection, recursion, sub-routines, divide-and-conquour stratergy ect.. As a beginning language, people would probably disagree but I don't recomment c#, it teaches some bad habbits with typing and as a high end refined language, has certain restricions and fallicies (I leaned alot about data structures from writing my own dynamic array type in pascal with pointers, however to recreate the experiance in c# would require an "unsafe{" esplosion :P) I learned a really basic idea of programming from messing around with an old Elonex laptop i found in the attic in BASIC, simple relatively low level languages such as BASIC and PASCAL are great to lean with..Logic without the added fluff. In any case, good luck with programming, 'tis a noble proffession, and check out the euler problems page, or PM me, [email]Lemmingz95@gmail.com[/email] if you needed to ask anything. [editline]19th January 2013[/editline] Also, if you want soming fun to aim towards, try a celluar autominaton, i.e. conway's game of life. With simple rules its relatively easy to write, and can be done as a console application. (for the love of god look up "Console.SetCursorPosition(x,y)" or whatever, instead or continually redrawing the thing and scrolling the window down at the speed of shit)
[QUOTE=Lemmingz95;39272842]i STRONGLY reccomend project euler tasks : [URL]http://projecteuler.net/problems[/URL].[/QUOTE] Holy shit, how didn't I know of this before?
[QUOTE=Mozartkugeln;39272775]You've got a semicolon after the condition in the if statement.[/QUOTE] Ah, didn't notice, thanks. [QUOTE]Also, you aren't outputting the result anywhere; you're just giving the variable a different value.[/QUOTE] ...ah, woops. I feel dumb. Gotta work on that. Thanks for informing me anyhow! [QUOTE=Lemmingz95;39272842]Just a suggestion, and by no means an insult to your intelligence, as your new, why don't you try a command-line based calculator to begin with, then move on to working with forms?[/QUOTE] It makes more sense logically, but the book I'm using to learn this is going rather fast. In hindsight, 257 pages seems rather short for a coding book, but it technically has a second course tailored around game design (Which I don't own). [QUOTE]I helped out with a course teaching programming in PASCAL to first-years this year, and i could easily get some of the help-documentation and tasks if you'd like, alternativly if your interested in maths aswell i STRONGLY reccomend project euler tasks : [URL]http://projecteuler.net/problems[/URL]. These have rather a steep learning curve but all require the use of fundamental statements and will help develop your technique and knolwedge of iteration, selection, recursion, sub-routines, divide-and-conquour stratergy ect.. [/QUOTE] I'll have to bookmark it! [QUOTE]As a beginning language, people would probably disagree but I don't recomment c#, it teaches some bad habbits with typing and as a high end refined language, has certain restricions and fallicies (I leaned alot about data structures from writing my own dynamic array type in pascal with pointers, however to recreate the experiance in c# would require an "unsafe{" esplosion :P)[/QUOTE] That is actually the language this book is based off of, so lucky me I guess. [QUOTE]I learned a really basic idea of programming from messing around with an old Elonex laptop i found in the attic in BASIC, simple relatively low level languages such as BASIC and PASCAL are great to lean with..Logic without the added fluff. In any case, good luck with programming, 'tis a noble proffession, and check out the euler problems page, or PM me, [email]Lemmingz95@gmail.com[/email] if you needed to ask anything.[/QUOTE] Alright, thanks! I'll try to remember to ask you if I have anything in dire need of being solved~ [QUOTE]Also, if you want something fun to aim towards, try a celluar autominaton, i.e. conway's game of life. With simple rules its relatively easy to write, and can be done as a console application. (for the love of god look up "Console.SetCursorPosition(x,y)" or whatever, instead or continually redrawing the thing and scrolling the window down at the speed of shit)[/QUOTE] Sounds neat (I googled it). Once I have a grasp of what I'm doing I'll be sure to give it a shot. And thanks for the SetCursorPosition tip, I'll try to remember that! [B]Edit:[/B] Also, I must have brain damage because despite reading about how to do it multiple times, I cannot FOR THE LIFE OF ME figure out how to make the results able to applied properly. I seemingly cannot convert it into a string to then output in the calculator, even though it should be possible. FFFFFFFFFF Coding is going to result in alot of lost hair over simple shit I'm overlooking like a braindead turkey. [SUB][SUB](ALSO IF I'M DOING IT THE WRONG WAY I WOULDN'T BE SUPRISED)[/SUB][/SUB]
[QUOTE=Mozartkugeln;39272949]Holy shit, why didn't I know of this before?[/QUOTE] Tell me about it...I used to sit, unable to think of what to do to "test myself" unti I found it :P, theres example solutions all over the web aswell to help.
I'll give you one piece of advice right now for projecteuler, Don't print out information in your for loop, it will make your code 4 times slower. Just print out after you have done your calculations.
[QUOTE=NateDude;39272971]Ah, didn't notice, thanks. ...ah, woops. I feel dumb. Gotta work on that. Thanks for informing me anyhow! It makes more sense logically, but the book I'm using to learn this is going rather fast. In hindsight, 257 pages seems rather short for a coding book, but it technically has a second course tailored around game design (Which I don't own). I'll have to bookmark it! That is actually the language this book is based off of, so lucky me I guess. Alright, thanks! I'll try to remember to ask you if I have anything in dire need of being solved~ Sounds neat (I googled it). Once I have a grasp of what I'm doing I'll be sure to give it a shot. And thanks for the SetCursorPosition tip, I'll try to remember that! [B]Edit:[/B] Also, I must have brain damage because despite reading about how to do it multiple times, I cannot FOR THE LIFE OF ME figure out how to make the results able to applied properly. I seemingly cannot convert it into a string to then output in the calculator, even though it should be possible. FFFFFFFFFF Coding is going to result in alot of lost hair over simple shit I'm overlooking like a braindead turkey. [SUB][SUB](ALSO IF I'M DOING IT THE WRONG WAY I WOULDN'T BE SUPRISED)[/SUB][/SUB][/QUOTE] Well, what's your calculation code now then? Sidenote, Instead of all these: [code] private void Number0Button_Click(object sender, EventArgs e) { NumberLabel.Text += "0"; } [/code] You could put all the buttons on the same event, and have the event say: [code] private void Number0Button_Click(object sender, EventArgs e) { NumberLabel.Text += ((Button)sender).Text; } [/code] Basically the "sender" object is the button that triggers the event. If you parse it as a button, like so: (Button)sender, you can get the text value of the button that you clicked on, in this case 0-9, the values you want to add. Note that this only works if all the objects that you assign this event to, are actually Buttons, otherwise it will crash. Also if that's a bit too much, then I understand.
[QUOTE=Lemmingz95;39272496]Hey, got a problemn, probably more math related, but this is the most-suitable place (I think).. Im currently developing a MAPF (Multi-agent-potential-field) based nav system for a tower-defence / pseudo-rts game that me an some freinds are working on as our end our 2 year project. Im fine on the theory, and am happy making all sorts of radius-based fields i.e fields that take a distance (r) from the attractor/repulsor: [CODE] (...) [/CODE] However now i need a, for lack of better words, "half conic" shaped field, that is a plane with a depressed, bisected cone of length d. Given a : position of vertex of the depressed cone. b : position of a unit i need a function to generate potentials, (scalar) of about -30 in the centre of the depression, fading to 0 away from the centre and stopping at length d. The closest i've got is (...)[/QUOTE] This may help: You can use a [URL="http://www.bindichen.co.uk/post/Fundamentals/bell-shaped-function.html"]bell-shaped[/URL] function extruded along (let's say [B]y[/B] axis), for example; the bell-shaped function: [code]f(x,a,b)=1/(1+abs(x/a)^(2*b))[/code] Where a changes the width of the bell and b displaces the inflexion point's y coord (see the previous link) now the 3d curve may be something like: [code]-f(x,0.25*y,1.5)*abs(y)[/code] [img]http://i.imgur.com/jRb0TBo.png[/img] I used 0.25*y as 'a' so the bell will be tapped when y =0, getting the cone-like shape. The bell's vertex is always at y=1, so by multiplying it by abs(y) you will get a 'xy-sliced double cone melt with the z=0 plane', the side view of the function will be similar to y=-abs(x), so just change abs(y) with other function if you need another shape (i mean [thumb]http://i.imgur.com/imzIz7z.png[/thumb]) I'm sorry but I have a huge lack of english vocabulary for maths.
Whats the best crossplatform C# GUI library? I dont really like the GTK# gui builder in monodevelop
Messing around with C++... Am I doing this right? [code] // Load shaders std::ifstream t("simple.vert"); std::stringstream vert; vert << t.rdbuf(); const char * vertexSource = vert.str().c_str(); [/code]
I require assistance with drawing more than one model in OpenGL. My code so far looks like this: Creating an enity: [cpp] vao = glGenVertexArrays(); glBindVertexArray(vao); vbo = glGenBuffers(); //Load vertex data into buffer glBindBuffer(GL_ARRAY_BUFFER, vbo); glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); ebo = glGenBuffers(); //load data into elementBuffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glBufferData(GL_ELEMENT_ARRAY_BUFFER, elementBuffer, GL_STATIC_DRAW); [/cpp] main draw loop: [cpp] glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); entity.draw(); entity2.draw(); [/cpp] Draw loop for an entity: [cpp] glBindVertexArray(vao); glBindBuffer(GL_ARRAY_BUFFER, vbo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); glDrawElements(GL_TRIANGLES, verticies, GL_UNSIGNED_INT, 0); [/cpp] No matter what order I draw the entities, only the one created first will be drawn.
[QUOTE=Burning Ninja;39277808]Messing around with C++... Am I doing this right? [code] // Load shaders std::ifstream t("simple.vert"); std::stringstream vert; vert << t.rdbuf(); const char * vertexSource = vert.str().c_str(); [/code][/QUOTE] Nothing wrong (except you didn't t.close()) but you can do this: [cpp] bool loadShader(GLenum type, GLuint& shader, std::string filename) { std::ifstream filestream (filename.c_str()); if (!filestream.good()) { std::cerr << "Failed to open shader \"" << filename << "\"\n"; return false; } std::string str; filestream.seekg(0, std::ios::end); str.resize(filestream.tellg()); filestream.seekg(0, std::ios::beg); filestream.read(&str[0], str.size()); filestream.close(); const char* source = str.c_str(); shader = glCreateShader(type); glShaderSource(shader, 1, &source, NULL); glCompileShader(shader); GLint compileSuccess; glGetShaderiv(shader, GL_COMPILE_STATUS, &compileSuccess); char compileLog[513]; if (compileSuccess == GL_FALSE) { glGetShaderInfoLog(shader, 512, NULL, compileLog); std::cerr << "Shader \"" << filename << "\" failed to compile. Error log:\n" << compileLog; glDeleteShader(shader); return false; } } [/cpp]
[QUOTE=Richy19;39277456]Whats the best crossplatform C# GUI library? I dont really like the GTK# gui builder in monodevelop[/QUOTE] I would recommend XWT, but a lot of the WPF backend is still missing and it has no designer. If you want to get shit done quickly, just use winforms as it'll run on all Mono-supported platforms (IIRC) even though it looks terrible, then later move to a better cross-platform GUI library. Just make sure you separate your actual code from the GUI code and it'll be pretty easy to switch.
Hey guys, I need help with some array recursion in Lua. Basically, what I have is this: [img]https://dl.dropbox.com/u/8416055/SAL_Recursion_001.jpg[/img] As you can see, it's a nested array. Now, what I want to do is, counting only leaves (_WEIGHT leaves included), find the n-th leaf, and return what that leaf is. This part I have down fine. But I [b]also[/b] need to return the entire path, from Decision, [b]to[/b] that leaf. Now, this works fine if the n-th leaf is in the first full array. For example, if n = 5, then the leaf is Decision.Build.Collector.UnitClosestToFriendlyBase. [b]However[/b], if the leaf goes beyond that first full array - say, n = 9 - then it fucks up. The proper 9th path is Decision.Build.Something.Else.ChoiceC. However, the way my recurser works is top-down, level-wise. It penetrates to the deepest level, counts top-to-bottom, and then recedes one level and continues. So it counts all the top arrays first, which isn't a big deal in itself. However, it also records the steps its take. And when it steps through an entire array that does not have the n-th element it is looking for, it keeps that array in record, resulting in correct output, as seen here: [img]https://dl.dropbox.com/u/8416055/SAL_Recursion_002.jpg[/img] Here is my recursor code. I kept the debug prints in there to help others better see what I am doing. [code]function SAL.RecursivelyIterate(src,goal,cur,keypath) if not cur then cur = 0 end if not keypath then keypath = {} end local last = {} print("Begin to step through table "..tostring(src)..". Cur is "..cur) for k,v in pairs(src) do last = {k,v} print("Last = {"..tostring(k)..","..tostring(v).."}") if (type(v)=="table") and (v._WEIGHT) then print("V is a table. Recursing through it. (Key = "..k..")") table.insert(keypath,k) local c,kp c,kp,last = SAL.RecursivelyIterate(src[k],goal,cur,keypath) cur = cur + c - 2 -- Jumping out of a table seems to double-count. -1 to alleviate that. Another -1 so it won't count this table and then its _WEIGHT. We want to just count the _WEIGHT. print("Finished iterating table; last is now {"..tostring(last[1])..","..tostring(last[2]).."}") else print("V is a value. Incrementing cur. (Key = "..k..")") cur = cur + 1 end print("Checking if cur >= goal. "..cur.." >=? "..goal..")") if cur >= goal then print("True. Returning.") return cur,keypath,last end end print("Got to the end of the line for table "..tostring(src).." with a cur of "..cur.." out of "..goal..". Returning.") return cur,keypath,last end[/code] The root "src" is the "Decision" seen in the first image. Anyone have suggestions of how I can form the record properly?
I have some issues in Scheme. [code](define (binom n k ) (cond ((#t (and (= k 0) (>= n 0))) 1) ((#t (and (= n 0) (> k 0))) 0))) [/code] Basically, this assignment requires us to write the binomial coefficient in Scheme. We have to return 0 if k = 0, and n >= 0, and return 1 if n = 0, and k > 0. It doesn't seem to be working, what am I doing wrong?
[QUOTE=Leonmyster;39281048]I have some issues in Scheme. [code](define (binom n k ) (cond ((#t (and (= k 0) (>= n 0))) 1) ((#t (and (= n 0) (> k 0))) 0))) [/code] Basically, this assignment requires us to write the binomial coefficient in Scheme. We have to return 0 if k = 0, and n >= 0, and return 1 if n = 0, and k > 0. It doesn't seem to be working, what am I doing wrong?[/QUOTE] Bear with me because I only know Common Lisp, but in a cond you have to put the condition first - you put #t first, which is always true, so the first result is always chosen. [code](define (binom n k) (cond (((and (= k 0) (>= n 0)) 1) ((and (= n 0) (> k 0)) 0))))[/code]
Does anyone know the best way to store a data stream in memory in c++ ? I have a function which gets called by libcurl when it receives a file. As arguments, I get 3 things: void * ptr which contains the data received; size_t size and size_t nmemb which, once multiplied together, represent the size of the data inside ptr. This function is called a non determined number of times, and the data is not always the same size. How can I save all the data progressively inside one variable ? My guess would be to make a bigass byte* variable where I insert data while keeping track on the position I am in, but I think there should be a better solution.
[QUOTE=account;39281198]Bear with me because I only know Common Lisp, but in a cond you have to put the condition first - you put #t first, which is always true, so the first result is always chosen. [code](define (binom n k) (cond (((and (= k 0) (>= n 0)) 1) ((and (= n 0) (> k 0))) 0)))[/code][/QUOTE] Thanks for the response, but it didn't solve the problem. Scheme is proving to be a lot harder than I expected. I'm only trying to get the base case working for now. I need to recursively call the rest of the binomial coefficient to finish it up, but I'll do that after I get base case working. I think I got it. [code](define (binom n k ) (cond ((= k 0) (>= n 0) 1) ((= n 0) (> k 0) 0)))[/code]
I'm trying to implement a functioning stack in C using an array, but it's not working properly. I think it's something to do with my "top" variable, but I'm not sure what. Entering a number should push it onto the stack, entering '.' should pop it off, and "List" should list the contents of the stack. Main [CODE] // stack.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include "stackops.h" int main(void){ char choice[100]; while(1){ printf("Enter a command:\n > "); scanf("%s", choice); if(choice[0] == '.'){ pop(); continue; } else if(isdigit(choice[0])){ push(atoi(&choice[0])); continue; } else if((choice[0] == 'l') || (choice[0] == 'L')){ if(choice[1] == 'i') listArray(); else printf("Error: invalid command\n\n"); continue; } else if(((choice[0] == 'e') || (choice[0] == 'E')) && (choice[1] == 'x')) exit(1); else{ printf("Error: invalid command\n\n"); continue; } } return 0; } [/CODE] Functions [CODE] // stackops.h #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> void pop(void); void push(int num); void listArray(void); [/CODE] [CODE] // stackops.c #include "stackops.h" int stack[10]; int top = 0; void pop(void){ if(top >= 0) top--; else printf("Error: stack empty\n\n"); printf("%i [%i]\n", top, stack[top]); return; } void push(int num){ if(top < 10){ stack[top] = num; top++; } else printf("Error: stack full\n\n"); printf("%i [%i]\n", top, stack[top]); return; } void listArray(void){ int i = 0; for(i = top; i >= 0; i--) printf("%i ", stack[i]); printf("\n"); return; } [/CODE]
[QUOTE=muckuruxx;39283053]I'm trying to implement a functioning stack in C using an array, but it's not working properly. I think it's something to do with my "top" variable, but I'm not sure what. Entering a number should push it onto the stack, entering '.' should pop it off, and "List" should list the contents of the stack. [/QUOTE] [cpp]int pop(void){ if(top > 0) top--; ..... return stack[top+1]; } [/cpp] And [cpp]void listArray(void){ int i = 0; for(i = top; i > 0; i--) printf("%i ", stack[i]); }[/cpp] You want to use > 0, not >= 0 for both of these, because otherwise top will decrease to -1 which will probably cause an access violation when you try to access that value. Also, pop always returns the popped value.
[QUOTE=account;39283174] You want to use > 0, not >= 0 for both of these, because otherwise top will decrease to -1 which will probably cause an access violation when you try to access that value. Also, pop always returns the popped value.[/QUOTE] Ah, okay. Thanks! It's been making me a little nuts, haha. I'm glad it was something small like that.
EDIT: I realized I mixed problems with a different class. Rate me dumb because I'm an idiot.
[QUOTE=A big fat ass;39261952]I'm having some issues with my Visual Basic Hitman Absolution disguise replacer. It's crashing for everybody with an error, but it doesn't crash for me or one of my friends. I've had 2 or 3 people testing the program as I was making it, and the older versions has worked for them up until this latest one. The thing is, I have absolutely no idea what has changed about it that is crashing for everybody except me and my friend. Here's the .exe. I downloaded it myself and it works fine, but it produces an error immediately on launch for others. [url]http://filesmelt.com/dl/Hitman_Absolution_Disguise_Replacer.zip[/url] I don't like asking to fix it, but I just have absolutely no idea what's causing it or where to start. The program works by asking you for your Hitman: Absolution folder, you pick it, then it finds out where the disguise files are and backs them up, then you can replace disguises from two lists. Here's the very sloppy source: [url]http://pastebin.com/ePbS6LVc[/url] This is the error someone reported. I can't replicate it.[/QUOTE] I have a rather odd follow-up to this question. I noticed the program was crashing on my netbook, so I decided to install Visual Studio on it so I can try debugging it. Except now that Visual Basic is installed, the program works fine on my netbook. This also makes sense considering my friend that the program works with also has Visual Studio installed. I didn't touch the framework version it uses, but I must have changed something that Visual Studio comes with that people trying to use the program don't have. Very strange. I was messing around with some of the project properties, but I can't think of anything that would have a dire effect on the program other than assembly information [editline]20th January 2013[/editline] Oh fuck me, I think all of that mess was just because I left in a visual basic power pack that I didn't even end up using. Nevermind then, it works now.
My problem is: I'm confused on where to find good tutorials, that will actually make me program something the next month. I found thenewboston, and I'm currently learning C++. Do you recommend him? Or should I find another place to lean, if yes, where? Regards
[QUOTE=Noztra;39287371]My problem is: I'm confused on where to find good tutorials, that will actually make me program something the next month. I found thenewboston, and I'm currently learning C++. Do you recommend him? Or should I find another place to lean, if yes, where? Regards[/QUOTE] Don't let people tell where you should and shouldn't learn. If whatever you're learning from is up to date and isn't giving you incorrect information, then why not use it? Especially if it's helping you. Personally I found [url]www.cplusplus.com[/url] to be a great online resource.
[QUOTE=DarkCybo7;39287397]Don't let people tell where you should and shouldn't learn. If whatever you're learning from is up to date and isn't giving you incorrect information, then why not use it? Especially if it's helping you. Personally I found [url]www.cplusplus.com[/url] to be a great online resource.[/QUOTE] I've used that before, and yes, it is great. I just find videos more interesting, therefor, I concentrate more on it :-)
Sorry, you need to Log In to post a reply to this thread.