|
[C]File i/o and Rot13
|
|
11-04-2009, 06:21 PM
Post: #1
|
|||
|
|||
|
This is a little program I wrote a couple days ago to, err, get back in the C 'mindset' ;). I hadn't coded C in a while, but I've started to like it a lot.
I'm posting it here for two reasons: 1. to hopefully help people who are learning to program w/ understanding file i/o and the rot13 encryption algorithm. (simple). That being said, feel free to ask me if you don't understand what something does, how how something works. and 2. To get some of the more advanced C programmer's advice / input. (*cough* g4143) Code: #include <stdio.h>And, since reading code in the code tags sucks, http://farout.pastebin.com/m29d42757 The comment at the bottom shows how it works :). |
|||
|
11-04-2009, 06:38 PM
Post: #2
|
|||
|
|||
|
I looked it it for two seconds and saw this:
Code: char rotateChar(int oldChar);They are global, you should never make anything global unless you 100% absoloutly need to (like a logger for debugging), particularly for a language like C, now I know C doesn't know what a class is, but it knows what a function is, and you clearly know that because you've made three declarations instantiating 3 functions globally, why? This can cause memory leaks on the stack/heap because it's globally accesable so it can be called without any access specifiers, not a good idea. -Systemerror
|
|||
|
11-04-2009, 06:40 PM
Post: #3
|
|||
|
|||
(11-04-2009 06:38 PM)Systemerror Wrote: They are global, you should never make anything global unless you 100% absoloutly need to (like a logger for debugging), particularly for a language like C, now I know C doesn't know what a class is, but it knows what a function is, and you clearly know that because you've made three declarations instantiating 3 functions globally, why? What do you suggest? That I put all my code in the main method? I'm good, thanks. |
|||
|
11-04-2009, 06:46 PM
(This post was last modified: 11-04-2009 06:48 PM by Systemerror.)
Post: #4
|
|||
|
|||
(11-04-2009 06:40 PM)scaryblackguy Wrote: What do you suggest? That I put all my code in the main method? I'm good, thanks. Well you could create a header with the function declarations, an implementation file with the function defintions and possibly create some access specifyers/use function pointers etc. -Systemerror
|
|||
|
11-04-2009, 06:53 PM
(This post was last modified: 11-04-2009 06:57 PM by scaryblackguy.)
Post: #5
|
|||
|
|||
(11-04-2009 06:46 PM)Systemerror Wrote: Well you could create a header with the function declarations, an implementation file with the function defintions and possibly create some access specifyers/use function pointers etc. No access specifiers in C, I don't see the use in overcomplicating my code with function pointers, and a header file for three functions that are less that 50 lines combined is overkill. Also, Systemerror, don't bother giving me advice when you implement retarded while loops and if's, in order to over-complicate your code to give people the impression that you're smarter than you are. http://www.hackforums.net/showthread.php?tid=169326 |
|||
|
11-04-2009, 07:03 PM
Post: #6
|
|||
|
|||
(11-04-2009 06:38 PM)Systemerror Wrote: I looked it it for two seconds and saw this: Please stop commenting when you don't know what you're talking about. There is no reason in this code to use classes. And, I'll note, this is C. There are no access modifiers. His code is secure enough as-is. |
|||
|
11-04-2009, 07:10 PM
(This post was last modified: 11-04-2009 07:13 PM by Systemerror.)
Post: #7
|
|||
|
|||
(11-04-2009 06:53 PM)scaryblackguy Wrote: No access specifiers in C, I don't see the use in overcomplicating my code with function pointers, and a header file for three functions that are less that 50 lines combined is overkill. It's not over-complicating anything, it's good programming standard to make a header to declare functions particularly which are used regularly or require global use, an implementation file to define those methods and then implement them with your entry point. I'm not sure if you know but C and C++ are mainly powerful for there flexible memory managment on the heap and stack, which is sometimes annoying because it's often tedious to ensure there are no memory leaks as you have to clean everything up, however it's worth it for the control and power you get, it's not like Java which has minimal mem managment and has it's own garbage collector - you have to do the dirty work, that said, your above source code is potentially open to memory leaks for the reasons I stated in my first post, that said, it's worth doing something to avoid that as that is one of the main factors in C. (11-04-2009 07:03 PM)p4bz Wrote: Please stop commenting when you don't know what you're talking about. There is no reason in this code to use classes. And, I'll note, this is C. There are no access modifiers. His code is secure enough as-is. I think you're the one who doesn't know what he's talking about... Firstly a mistakenly said access specifiers, what I meant was function pointers which can be called and returned. More importantly, I never once said there is need for classes, C doesn't know what a class is, I think you're thinking of C++, and no for the above reasons his code is not secure. -Systemerror
|
|||
|
11-04-2009, 07:22 PM
Post: #8
|
|||
|
|||
(11-04-2009 07:10 PM)Systemerror Wrote: It's not over-complicating anything, it's good programming standard to make a header to declare functions particularly which are used regularly or require global use, an implementation file to define those methods and then implement them with your entry point. I'm not sure if you know but C and C++ are mainly powerful for there flexible memory managment on the heap and stack, which is sometimes annoying because it's often tedious to ensure there are no memory leaks as you have to clean everything up, however it's worth it for the control and power you get, it's not like Java which has minimal mem managment and has it's own garbage collector - you have to do the dirty work, that said, your above source code is potentially open to memory leaks for the reasons I stated in my first post, that said, it's worth doing something to avoid that as that is one of the main factors in C. First of all, don't lecture me on the benefits of C and C++ vs. Java, when you've yet to prove that you have decent knowledge of either language, or of decent programming practice. I'd appreciate it if you would stop commenting on this thread, the next time this program segfaults, I'll contact you. |
|||
|
11-04-2009, 07:27 PM
Post: #9
|
|||
|
|||
(11-04-2009 07:22 PM)scaryblackguy Wrote: First of all, don't lecture me on the benefits of C and C++ vs. Java, when you've yet to prove that you have decent knowledge of either language, or of decent programming practice. Everything I just told you about your program is fact, take it or leave it I don't really care but you obviously can't take constructive critisism from someone who clearly knows a lot more than you about C and C++. -Systemerror
|
|||
|
11-04-2009, 08:21 PM
(This post was last modified: 11-04-2009 08:22 PM by Psycho.)
Post: #10
|
|||
|
|||
|
Why do you always talk to people in a condescending attitude, Systemerror? You're a prick.
irc.malvager.com/hackforums - official HF IRC
If you need any help at all with IRC, feel free to PM me. |
|||
|
« Next Oldest | Next Newest »
|

Home
Upgrade
Search
Member List
Help
IRC
Contact






