-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path1.cpp
36 lines (31 loc) · 772 Bytes
/
1.cpp
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
#include <stdio.h>
#include <stdlib.h>
/**
* An object that contains two character arrays, one determined by the user, and one that contains a shell command.
*/
class Test{
public:
/**
* Set the command buffer to the command "ls".
*/
Test(){
command[0] = 'l';
command[1] = 's';
command[2] = '\0';
}
/**
* Read a string from standard input, then execute the command in the command character array.
*/
void a(){
scanf("%s", buffer); //read from standard input until null byte
system(command); //execute the command in the command character array
}
private:
char buffer[10]; //stores a 10 character string
char command[10]; //stores a 10 character command passed to the
};
int main(){
//this object is stored on the stack
Test aTest = Test();
aTest.a();
}