-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhello_worldo.cpp
More file actions
58 lines (50 loc) · 1.02 KB
/
Copy pathhello_worldo.cpp
File metadata and controls
58 lines (50 loc) · 1.02 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
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
// void create_file() {
// FILE *file;
// file = fopen ("test_file.txt","w");
// if (file!=NULL) {
// fprintf(file,"Novo arquivo");
// fclose (file);
// } else {
// printf("Arquivo não encontrado\n");
// }
// printf("Arquivo salvo\n");
// }
void test_file() {
FILE *file;
file = fopen("test_file.txt","r");
if (file != NULL) {
printf("File found!\n");
fclose (file);
} else {
printf("File not found :(\n");
}
}
void pid_test() {
pid_t pid = getpid();
printf("My pid is %d\n",pid);
}
void env_variable() {
char env_var_name[] = "HOME";
char* var = getenv(env_var_name);
if (var != NULL)
printf("Variable %s found : %s\n",env_var_name,var);
else
printf("Variable not found :(\n");
}
void test_uts() {
const size_t max_len = 100;
char nome[max_len];
gethostname(nome, max_len);
printf("[Hostname]=%s\n", nome);
}
int main() {
test_file();
pid_test();
env_variable();
test_uts();
return 0;
}