-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67d8c74
commit 89b9ebc
Showing
4 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |