Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Ectara

Member Since 27 Feb 2009
Offline Last Active Today, 01:58 PM

#5063076 Why isn't this moving?

Posted by Ectara on 19 May 2013 - 03:49 PM

if (PlayerLocationy == 378)
{
Message = DeniedMessage;
ApplySurface((ScreenWidth - Message->w)/2,(ScreenHeight - Message->h + 420)/2,Message,Screen,NULL);
Message == NULL;
}

if (SDL_KEYDOWN == SDLK_y)
{
QUIT == true;
}

I am almost 100% positive you mean to use a single equals sign here. Double equals compares them for equality, and then the result is discarded here with nothing happening.

 

else
{
PlayerLocationy =+ 42;
ApplySurface(0,421,Sprites,Screen,&TextBox);
}

else
{
PlayerLocationx =- 42;
ApplySurface(0,421,Sprites,Screen,&TextBox);
}

I can't quite place what language you must be getting this from, but in compound assignment operators, the equals sign always comes last. "PlayerLocationy =+ 42;" is parsed the same as "PlayerLocationy = +42;", which isn't what you wanted. Likewise, "PlayerLocationy =- 42;" is the same as "PlayerLocationy = -42;".




#5063053 fstream relative dir?

Posted by Ectara on 19 May 2013 - 12:42 PM

Relative paths work for me with G++. If it makes a difference, try using proper backslash separators, and make sure that your current working directory is in C:\Editor\SomeDirectory.




#5062101 Breadth vs. Depth?

Posted by Ectara on 15 May 2013 - 01:29 PM

I'd say pick one and stick to it. Skills transfer, but there's no good in being mediocre in multiple languages. If after some time, you find the features of another language more alluring, or you feel that the other language is a better tool for the job, then by all means, make the switch. When getting early experience, try not to complicate it by also having to learn the nuances of multiple languages, and their standard libraries.

EDIT: I should probably clarify on "make the switch". Every programmer has a language they like more than the rest, but don't feel like you must use only one language ever, and that you must choose one to use forever. When I say "make the switch", I mean use the chosen language for the task at hand; another task might be better suited for a different language.


#5061212 How would you concatenate an array of strings together?

Posted by Ectara on 11 May 2013 - 10:20 PM

char buffer[4096]; // adjust
buffer[0]='\0';
 
for(int i=0;i<array_size;i++){
strcat(buffer,string_array[i]);
}

 

You can implement a two pass system as well, the first pass can determine how big the buffer must be.

I want to provide constructive criticism to say why you are getting downvotes, because it is frustrating to receive a negative reputation with out explanation.

That is the wrong language; there is no strcat() that I'm aware of in C#, and character arrays are not what is being used. That's also one of the least efficient ways to concatenate a collection of strings, due to having to count the length of the buffer each time you concatenate the string, which takes longer and longer.




#5061209 calculator app

Posted by Ectara on 11 May 2013 - 10:10 PM

A simple thing to add is a way to assign S to X, and choose another operator and Y to perform a new operation based on the result of the last. I wouldn't really say you need to add anything to the logic, since it is a GUI for some of the most basic things a machine can do, but as a learning experience, here is a path you could try to expand what you know.




#5058821 String

Posted by Ectara on 03 May 2013 - 01:34 AM

We cannot do your homework for you. However, if you provide what you have so far, and explain where you are having trouble, we would be happy to help.




#5058147 c++ code examples

Posted by Ectara on 30 April 2013 - 01:27 PM

cplusplus.com is rife with errors and misinformations. I'd stick to another site, until you are good enough to spot an error in their code before wondering why not only does their example not work, but their specifications are missing or impossible.

 

I've tried emailing in corrections, but he didn't quite get what I was saying; he kept replying with a description of what the functions are supposed to do, despite me telling him that his example function does not do that at all.




#5055145 Servers and Encryption

Posted by Ectara on 19 April 2013 - 11:58 PM

The first question that comes to mind is why the password is even stored server-side at all? It is very common to simply store a hash of the password, plus a couple salts, and check if the hash of the password on the client's side matches the one on file. If someone gets your hash, there isn't much that they can do with it; hashing is one-way by nature, so if they get your hash, they can't figure out what the original password is. For this reason, if the user loses their password, a new one must be generated, because the old one can't be retrieved.

So, I feel the question should be less of how do I prevent the inevitability of someone being able to decrypt my password, and more of how do I avoid ever having something that can be stolen?




#5050514 Unicode storage

Posted by Ectara on 06 April 2013 - 12:03 AM

A quick and dirty explanation:

UTF-8 is variable width, but is not endian-specific. Great for storage and transmission.

UTF-16 is variable width, and is endian-specific. It's limitations are also is the reason why the Unicode standard restricts to code points less than 0x10FFFF. Avoid like the plague.

UTF-32 is fixed width, and is endian-specific. It is faster to iterate through an array of code points in both directions, but requires more space.


If you need more in-depth information, a dedicated guide would be best.

 

Also, if you are doing your own text handling, avoid wchar_t unless you are dealing with something very close to the system API. Not only does one code point not necessarily correspond to one character, but one wchar_t need not correspond to a whole code point, such as with UTF-16. To make matters worse, wchar_t and wide-char strings aren't required to use UTF-16 or UTF-32. They must be a unit that can hold all characters used by the system. Symbian uses UCS-2 strings.




#5050091 This error has me perplexed.

Posted by Ectara on 04 April 2013 - 02:36 PM


Also, see if there's some sort of memory debugger that you can use. One of the first programs I turn to for things like this is Valgrind, which would give you a heads-up once various memory errors occur.

 
"VS2012 express edition"
 
Valgrind does not run on Windows.
I know. I never said it did. Actually, more accurately, it does: http://sourceforge.net/projects/valgrind4win/, but it doesn't work with VS.
 
 

Now if I uncomment the line "ss << 15;" it will compile and run fine. Notice how the function is never called.

One thing I can think of is that with the line uncommented, that templated member function becomes instantiated. Does it make a difference if you copy the body of this function to some other point in the code?


#5038753 Basic question

Posted by Ectara on 03 March 2013 - 10:05 AM

couldn't you ignore punctuation and do something like "if (input_string.contains("twelve") then ++twelve_counter"?

If you know your input precisely (and probably already know how many of each word).

Otherwise, you could easily catch words that appear in a longer, different word, resulting in erroneous counts.




#5037651 Want to learn programming...again

Posted by Ectara on 28 February 2013 - 10:17 AM

Sigh...please read my post properly before replying...



"Well, C and C++ are considered the same language but there are some differences beside the obvious use of OOP in C++..."


That statement is still incorrect, no matter how you emphasize it. They are nowhere near considered the same language, and there are many differences. Their standards move at different paces, and disregarding even OOP, there are a surprisingly large amount of things that C supports and allows that C++ does not, and vice versa. Not to mention, a wealth of different keywords (and meanings for them), with new types that are exclusive to C or C++. C++ started out before the first ANSI C standard; it is in many ways not a superset of the language, because it wasn't wholly built upon it. In many ways, it was influenced by the success of C as a programming language, and borrowed its syntax, but it was developed alongside it, and separately.

To keep saying that they are almost the same is just not true. There are many code samples that will compile differently (or not at all) in either language. Perhaps try to elaborate on your point so that you don't confuse newcomers? That's the reason people are calling you on it.

Anyway, I think learning OOP straight off the bat is going to leave many beginners feeling lost. I've seen it on the courses I have taken where some have withdrawn because they jumped the gun with procedural programming. One has enough on their plate with loops, control statements, data types, opening and closing files without throwing OOP in to the mix. Yes, its an important concept, but one thing at a time, no?


I agree with this, but it might depend on the teacher. My teacher for C++ was terrible. She didn't know what she was doing, and was teaching C with Classes. Everything went in a class, even things that held no state; they should have been free functions in a namespace, but she didn't teach namespaces. We had char arrays for everything, because she didn't teach the standard templates. We got ripped off in our education. As a result, my code was absolutely horrible, and it took me many years of finally swearing off classes because I didn't need them, before I could learn how important they were.

Often, going without a feature and doing things the hard way is the best way to learn to appreciate a feature.


#5037434 Want to learn programming...again

Posted by Ectara on 27 February 2013 - 08:28 PM

You can't go wrong with either C++ or Java as a primary language. C++ is the darling of the games industry whilst Java can be used for Android games.

 

However, if you are learning from scratch then its wise to leave alone OOP languages until you have the basics of structured programming nailed. Both C or JavaScript are ideal beginner languages and share almost identical basic syntax with both C++ and Java. Well, C and C++ are considered the same language but there are some differences beside the obvious use of OOP in C++...

I do agree that starting with C before C++ is a good decision (it helped me quite a bit), but I can't agree that C and C++ are considered the same language.




#5037277 Writing my own programming language

Posted by Ectara on 27 February 2013 - 01:38 PM

I prefer semi-colons and marking blocks with braces because it feels explicit and unambiguous. The statement will not end without something that marks the end of it, and blocks begin and end in only one way that is indisputable; considering things like JavaScript's optional semi-colons, which sometimes results in a different expression if you ended the line with a semi-colon and without, I say that when people consider line endings to terminate statements, it isn't always clear how it should be handled. If the statement is long enough that I should break it into two lines, how do I bring it to the next line without accidentally marking the end of the statement, and how do I do it in a way that the compiler is guaranteed not to misunderstand my intention? If the answer is add more whitespace, then chances are, I won't use the language unless someone pays me. Everyone has a different style, and languages that try to dictate how many spaces I must use in order for it to have syntactic significance rub me the wrong way.

Indentation is good. The language absolutely requiring it, I don't know about that.




#5036183 Get unique IDs by reading the Instruction Pointer Register

Posted by Ectara on 24 February 2013 - 04:16 PM

The compiler says: cannot convert parameter 1 from 'long' to 'int &'. GEN_ID is defined as long :/


Wait, why does the function take a reference to an int? It provides no benefit over passing the int by value, and will likely result in a penalty for the level of indirection. The only reason I can see for someone to do that is if the function modifies the referred to value.

Just making sure the function isn't now modifying a temporary value, thinking it is making a change to the value passed to the function.




PARTNERS