-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell_toets.cpp
More file actions
86 lines (74 loc) · 2.3 KB
/
Copy pathshell_toets.cpp
File metadata and controls
86 lines (74 loc) · 2.3 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <vector>
using namespace std;
void getOptions(int,char**,char*);
int main(int argc, char **argv)
{
pid_t pid; // integer that can store a process ID (use pid_t for portability)
if ((pid = fork()) == -1) // system functions also set a variable called "errno"
{
perror("fork"); // this function automatically checks "errno"
// and prints the error plus what you give it
return EXIT_FAILURE;
}
// ---- by when you get here there will be two processes
/*
Hy voer eers die parent proses uit en dan kom hy later weer terug vir die ander een.
Dis asof hy in 'n loop is maar ek weet nie wat aangaan nie.
*/
if (pid == 0) // child process
{
cout << "Input parameters:" << endl;
for(int i = 0; i < argc; ++i)
{
//cout << argv[i][0] << endl;
//as dit 'n option is
/*if(argv[i][0] == '-' && (unsigned)strlen(argv[i]) == 2)
cout << argv[i] << endl;*/
//as dit 'n argument is
if(argv[i][0] != '-')
cout << argv[i] << endl;
else
cout << "Don't recognize this character: " << argv[i] << endl;
}
//char* v = new char[3];
vector<char> v;
getOptions(argc, argv, v);
}
else // parent process
{
std::cout << "Doen die parent funksie se goed." << pid << std::endl;
}
return EXIT_SUCCESS;
}
//&& (unsigned)strlen(_argv[i]) > 1
/*void getOptions(int _argc, char** _argv, char* _options)
{
for(int i = 0; i < _argc; ++i)
if(_argv[i][0] == '-')
{
*_options = _argv[i][1];
cout << _options << endl;
_options++;
}
}/**/
/*
- Hulle het hier waar hulle die & voor die vektor sit om te se dis die pointer na
die vektor toe seker.
- Doen 'n toets waar jy kyk hoe hulle die vektors tussen die funksies stuur.
*/
/*
void getOptions(int _argc, char** _argv, vector<char> &_options)
{
for(int i = 0; i < _argc; ++i)
if(_argv[i][0] == '-')
{
//die * om te se dat die waarde van die pointer is
_options.push_back((char)_argv[i][1]);
cout << _options[i-1] << endl;
}
}/**/