Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
AnamikaSanjay committed Aug 16, 2023
1 parent 67d8c74 commit 89b9ebc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,56 @@
# CommandLineMaster-C
Dive deep into the intricacies of command line arguments in C with the CommandLineMaster-C repository. This comprehensive guide will take you from the basics to advanced usage, ensuring you gain a profound understanding of this essential programming concept

# CommandLineMaster-C

## Table of Contents
- [Introduction](#introduction)
- [Reading Command Line Arguments](#reading-command-line-arguments)
- [Understanding argz and envz](#understanding-argz-and-envz)
- [Contribution](#contribution)
- [License](#license)

## Introduction
Command line arguments are parameters provided to a program when it is invoked. These arguments allow users to specify different inputs without modifying the program's source code.

For instance, in the command `ls -l`, `ls` is the program and `-l` is the command line argument that instructs the program to display the files in a long format.

## Reading Command Line Arguments
In C, command line arguments can be read using the `argc` and `argv` parameters of the `main()` function. Here's a brief explanation:

- `argc`: Stands for "argument count". It represents the number of arguments passed to the program, including the program's name.
- `argv`: Stands for "argument vector". It is an array of strings representing the individual arguments provided to the program.

Here's a simple example:

```c
#include <stdio.h>

int main(int argc, char *argv[]) {
printf("Number of arguments: %d\n", argc);
for (int i = 0; i < argc; i++) {
printf("Argument %d: %s\n", i, argv[i]);
}
return 0;
}
```
![](/Screenshot%20from%202023-08-16%2018-14-10.png)
# Understanding argz and envz
`argz` and `envz` are interfaces used for argument and environment vector manipulation in C, especially with GNU extensions.
- **argz**: Represents a sequence of strings packed into one allocated block of memory, separated by null bytes (`\0`), and terminated by a double null byte (`\0\0`).
- **envz**: It's similar to `argz` but is used specifically for environment variables.
These interfaces provide a more dynamic way to manipulate command line arguments and environment variables compared to traditional string arrays (`argv` and `envp`). Functions like `argz_add()`, `argz_delete()`, `envz_add()`, and `envz_remove()` allow for easy and dynamic modifications.
## Contribution
If you'd like to contribute to CommandLineMaster-C, please fork the repository and submit a pull request. We welcome any valuable additions and feedback!
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
Binary file added Screenshot from 2023-08-16 18-14-10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added simple
Binary file not shown.
9 changes: 9 additions & 0 deletions simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <stdio.h>

int main(int argc, char *argv[]) {
printf("Number of arguments: %d\n", argc);
for (int i = 0; i < argc; i++) {
printf("Argument %d: %s\n", i, argv[i]);
}
return 0;
}

0 comments on commit 89b9ebc

Please sign in to comment.