Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

First C++ Project (Ghoul Script Configuration File Parser)


deathtaker26
 Share

Recommended Posts

@S.J.R.:

> I wasn't sure whether you were saying the goto-keyword was actually pretty or not. Apparently not, so you can safely ignore whatever I said.
> You've posted three snippets thus far, none really applying what I said about indentation and styling.

Oh ^_^ <3
Link to comment
Share on other sites

@Captain:

> Also instead of using std:: always, just insert this at the top of the source file below the headers;
> ```
> using namespace std;
>
> ```

Actually I heard it was bad practice to do this when you're starting C++ it's why I didn't on my main function

> You've posted three snippets thus far, none really applying what I said about indentation and styling.
>
> You still don't seem to comprehend neither literate programming neither the use of comments, even though I've described both.

well yeah you told me that my indentation was horrible but how?
Link to comment
Share on other sites

@Crest:

> well yeah you told me that my indentation was horrible but how?

The amount of scopes being nested into each other defines the depth of the scope, and therefore the amount of tabs to be used. Every time you enter a new scope, the depth gets incremented. Every time you leave a scope, the depth gets decremented. The curly braces themselves aren't indented to the new depth.

An example:
```
#include
#include
#include

typedef struct point_t                  point_t;

struct point_t
{
  int iX;
  int iY;
};

double distance(point_t objA, point_t objB)
{
  int iDistanceX = objA.iX - objB.iX;
  int iDistanceY = objA.iY - objB.iY;

  return sqrt(iDistanceX * iDistanceX + iDistanceY * iDistanceY);
}

int main(int argc, char *argv[])
{
  point_t objPointList[2];

  if (argc <= 4)
  {
    printf("Usage: %s \n", argv[0]);

    return -1;
  }

  objPointList[0].iX = atoi(argv[1]);
  objPointList[0].iY = atoi(argv[2]);
  objPointList[1].iX = atoi(argv[3]);
  objPointList[1].iY = atoi(argv[4]);

  printf("The distance is: %lf.\n", distance(objPointList[0], objPointList[1]));

  return 0;
}

```

Yours faithfully
  S.J.R. van Schaik.
Link to comment
Share on other sites

@S.J.R.:

> The amount of scopes being nested into each other defines the depth of the scope, and therefore the amount of tabs to be used. Every time you enter a new scope, the depth gets incremented. Every time you leave a scope, the depth gets decremented. The curly braces themselves aren't indented to the new depth.
>
> An example:
> ```
> #include
> #include
> #include
>
> typedef struct point_t                  point_t;
>
> struct point_t
> {
>   int iX;
>   int iY;
> };
>
> double distance(point_t objA, point_t objB)
> {
>   int iDistanceX = objA.iX - objB.iX;
>   int iDistanceY = objA.iY - objB.iY;
>  
>   return sqrt(iDistanceX * iDistanceX + iDistanceY * iDistanceY);
> }
>
> int main(int argc, char *argv[])
> {
>   point_t objPointList[2];
>  
>   if (argc <= 4)
>   {
>     printf("Usage: %s \n", argv[0]);
>    
>     return -1;
>   }
>  
>   objPointList[0].iX = atoi(argv[1]);
>   objPointList[0].iY = atoi(argv[2]);
>   objPointList[1].iX = atoi(argv[3]);
>   objPointList[1].iY = atoi(argv[4]);
>  
>   printf("The distance is: %lf.\n", distance(objPointList[0], objPointList[1]));
>  
>   return 0;
> }

> ```
>
> Yours faithfully
>   S.J.R. van Schaik.

Oh I see, I'll fix that.
Link to comment
Share on other sites

[http://www.cprogramming.com/tutorial/c++-tutorial.html](http://www.cprogramming.com/tutorial/c++-tutorial.html)

That's what I used when I was first starting in C++. Also, it's best to use

```
using namespace std;
```
at the top. I think the only reason you wouldn't want to use it is so it doesn't pollute the global namespace with loads of names that you won't use. It may potentially lead to the clashing of names, but I doubt it.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...