-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstore-argument-as-char.c
29 lines (27 loc) · 986 Bytes
/
store-argument-as-char.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// C example by Darren Rainey https://github.com/DarrenRainey
#include <stdio.h> // Include standard C header libary file
#include <string.h> // Include C string header file
int main(int argc, char *argv[])
{
char buffer[1024]; // Create a char called buffer with a size of 1024
if(argc > 1) // Check if there are any command arguments other than the program name
{
// Check for input argument
if(strcmp(argv[1], "--input") == 0) // Check if a command argument is a string called "--input"
{
// Store second argument in buffer
strcpy(buffer, argv[2]); // Copy string into buffer
// Print Buffer
printf("Buffer Contains String : %s\n",buffer);
}
else // If argument does not contain "--input"
{
printf("%s --input \"hello world\"\n",argv[0]); // Print program name and help information
}
}
else // If no arguments supplied
{
printf("%s --input \"hello world\"\n",argv[0]); // Print program name and help information
}
return 0; // Exit if no errors
}