Question: I want to get `carData.json` file from a server using `AngularJS`.

Here is how I have structured it:

I have a `services.js` file (inside of `js` forlder) where I hold all of my `services` and `factories`. Here is the `factory` that I use to get `carData.json` file from a server:

```
carApp.factory('getAllCars', function($http){
    return {
        get: function() {
            return $http.get('data/carData.json');
        }
    };
});

```

I also have a `CarsByReviewCtrl` controller that uses the `carData.json` file for its purposes:

```
carApp.controller("CarsByReviewCtrl", function($scope, getAllCars) {
    getAllCars.get().success(function(data){
        $scope.allCars = data;
    }).error(function(data, status, headers, config) {
      alert("AJAX failed")
    });
    $scope.carList = [];
    console.log($scope.allCars);
    ...

```

And finally here is the end of my `.html` file where I pass these `.js` files. (I have called the controller in the middle of my `html` file)

```
        <script type="text/javascript" src="js/controllers/CarsByReviewCtrl.js"></script>
        <script type="text/javascript" src="js/services.js"></script>
    </body>
</html>

```

Now, if I run my app and open the console, I would get the output of `undefined`, instead of javascript object that I got from the server.

**What have I done wrong and how can I fix that?**

Answer: 
You need to first open directory for which you need to list files after that you need to read directory.

Add **#include**  for using apis.

```
#include <dirent.h>

/* open the directory "/home/" for reading. */ 
DIR* dir = opendir("/home/users");

entry = readdir(dir)); //files or directories in /home 

//Add logic to verify entry is file or directory

```

Refer this thread <http://www.cpp-home.com/tutorials/107_6.htm>
the function 

```
system("ls")

```

is just firing the command but you are missing what the output of the command *ls* is.
You need to capture it.
In [this other thread](https://stackoverflow.com/questions/478898/how-to-execute-a-command-and-get-output-of-command-within-c) it's explained how to do it.