|
|

About this thread:
I've decided to start a single thread to track progress on different projects I am working on (whether it be school related or not). I'd like constructive criticism from the community, while keeping in mind that I have had almost no real experience with programming before this last semester of college. If you can give me an example of how I can do something in a better way then, by all means, share. Also, if you have any suggestions for generally improving my project (naming, conventions, whatever), please post them. All of these projects will be written in C.
I expect a detailed reason or argument on your point, advice, whatever (if applicable/possible, of course). Links to reputable resources are very good.
Current project:
Character creation program
I've decided to create a very basic character creation and saving system. I'll use structs for the players and an item system later. I'll also use enums for a rights system later. I've written a small objective list...
Spoiler for PlayerSystem.txt:
I've begun work on it and in about 10 minutes I've come up with this:
Spoiler for playerEntity.h:
Spoiler for playerEntity.c:
Spoiler for main.c:
Please understand that this is just an exercise to help me grasp the use of structs, file i/o, enums, and headers in C.
Good job! This is clear and very well written. Just a few questions. Why are you using the following libraries?
I have't checked the documentation but I'm assuming the 'put' function defined there? If so, since you are already using standard input output wouldn't you just use printf for regular output statements?#include <stdbool.h>
#include <ctype.h>



Sorry for the double post.
What would be the difference between using:
and not using a pointer? I mean I understand the difference, but I see a lot of example programs from others using this pointer instead of a regular variable declaration.Code:char* userInput[256];

Updated the OP with a Java version of reverseString. Not sure how to handle the possibility of a buffer overflow in Java at this time.
I'm about ready to move on to a new project. I'm thinking a pig-latin converter would be a good project. Thoughts?
triplePost++;

Updated OP with new project. This one should prove a bit more of a challenge than any other.
I'd like to ask for input on any usage of pointers/pass by reference in my program if I should do something different and use pointers or not. Any other constructive criticism is welcome, too.
Good job so far! I really have doubts when using scanf because it only reads up until the first space character. Although in a situation like this, its fine. When prompting for data be sure to use something more secure like fgets.Code:/* * This project creates a simple player entity system with a simple item * system, rights system, and character saving. This project is for * learning experience. * * Created on: Feb 29, 2016 */ #include <stdio.h> #include "playerEntity.h" void startup(); char getUserInput(); int main(int argc, char* argv[]) { startup(); return 1; } void startup() { printf("Welcome.\n"); printf("This is a basic character-creation program.\n"); printf("Have you created a character? [y/n]\n"); if(getUserInput() == 'y') { //TODO: prompt for character name and load file } else if(getUserInput() == 'n') { //TODO: prompt for character name and creation } else { printf("That input is not accepted.\n"); getUserInput(); } } char getUserInput() { char userKey = '\0'; scanf("%c", &userKey); return userKey; }
Also
You are calling the getUserInput function although the program is terminating after that, you are doing nothing with the value that is returned.Code:else { printf("That input is not accepted.\n"); getUserInput(); }
It's the least of my concerns but usually i have my functionof type struct player.Code:initPlayerChar
Also, its great that you're learning pointers as well as i/o. Also take a look at memory allocation. Learn malloc and a little about what happens behind the scenes in terms of stack and heap!
Careful when you use Pass by reference and pass by address.
Pass by reference is when the compiler makes a copy of the variable argument in the parameter. The actual value never changes.
Pass by address is actually sending the variable address to the function. The actual value does change.
Seems like you're on the right path with documentation, and style looks great. I personally like to follow c99 standard. If you are using the command like GCC to compile then
the it goes as follows.
Nevertheless great job! Will be keeping up with this thread to see your progress.Code:gcc -Wall -stc=c99 main.c playerEntity.c -o Program
| « need basic help | Finding closest object » |
| Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |