void mystrcpy(char *to, char *from)
{
while((*to++ = *from++))
;
}
#include <iostream>
#include <cstdio>
using namespace std;
void mystrcpy(char *to, char *from);
int main()
{
char str1[20], str2[20];
cout << "enter string: ";
gets(str1);
mystrcpy(str2, str1);
cout << "string copiet: " << str2;
cin.get();
return 0;
}
void mystrcpy(char *to, char *from)
{
while((*to++ = *from++))
;
}
#include <iostream>
using namespace std;
int main()
{
double **p = 0;
p = new double *;
int size;
cout << "Input size: ";
cin >> size;
*p = new double[size];
for (int i = 0; i < size; i++)
*(*p + i) = 0;
**p = *(*p + size - 1) = 2;
cout << "size: " << size << endl;
for (int i = 0; i < size; i++)
cout << *(*p + i) << " ";
cout << endl;
delete [] *p;
delete p;
p = 0;
return 0;
}
[guest@localhost cpp]$ .iso++ t.cpp -o t
[guest@localhost cpp]$ ./t
Input size: 10
size: 10
2 0 0 0 0 0 0 0 0 2
[guest@localhost cpp]$
Как это решается в серьезных проектах ?
Раньше просто писал
cin.get()
cin.get()
достало
system(“pause”)
getch()
тоже костыли !
#include <stdio.h>
struct a {
int a, b, c;
};
struct b {
double a, b, c, d;
};
struct c {
char s[100];
};
struct d {
int a, b, c;
double n[10];
};
union x {
struct a a;
struct b b;
struct c c;
struct d d;
};
typedef struct {
enum { A, B, C, D } type;
union x value;
} Obj;
int main(void)
{
Obj objects[100], *pobj;
int n;
int i;
objects[0].type = A;
objects[0].value.a.a = 1;
objects[0].value.a.b = 2;
objects[0].value.a.c = 3;
objects[1].type = B;
objects[1].value.b.a = 1.5;
objects[1].value.b.b = 2.5;
objects[1].value.b.c = 3.5;
objects[1].value.b.d = 4.5;
objects[2].type = C;
sprintf(objects[2].value.c.s, "abc");
objects[3].type = A;
objects[3].value.a.a = 4;
objects[3].value.a.b = 5;
objects[3].value.a.c = 6;
n = 4;
for (i = 0; i < n; i++) {
pobj = objects + i;
switch (pobj->type) {
case A:
printf("A: %d %d %d\n",
pobj->value.a.a,
pobj->value.a.b,
pobj->value.a.c);
break;
case B:
printf("B: %g %g %g %g\n",
pobj->value.b.a,
pobj->value.b.b,
pobj->value.b.c,
pobj->value.b.d);
break;
case C:
printf("C: %s\n", pobj->value.c.s);
break;
case D:
printf("D: %g\n", pobj->value.d.n[0]);
break;
}
}
return 0;
}
[guest@localhost c]$ .ansi t.c -o t
[guest@localhost c]$ ./t
A: 1 2 3
B: 1.5 2.5 3.5 4.5
C: abc
A: 4 5 6
[guest@localhost c]$
[guest@localhost t]$ ls
[guest@localhost t]$ touch cat
[guest@localhost t]$ echo hello >file.txt
[guest@localhost t]$ ll
итого 4
-rw-rw-r--. 1 guest guest 0 дек 30 11:32 cat
-rw-rw-r--. 1 guest guest 6 дек 30 11:32 file.txt
[guest@localhost t]$ *
hello
[guest@localhost t]$
>>> s = 'Привет!!!'
>>> ''.join(format(i, '02X') for i in s.encode('utf-16-be'))
'041F04400438043204350442002100210021'
>>>
if (cond)
;
else
statement;
if (cond) {}
else {
statement;
}
if (cond)
if (cond)
if (cond) {
statement;
statement;
}
else
statement;
else
statement;
if (cond) {
if (cond) {
if (cond) {
statement;
statement;
}
else {
statement;
}
}
else {
statement;
}
}
"За плечами" C# и Scala на хорошем уровне, много других на удовлетворительном
#!/bin/bash
func()
{
local tab date freq
local text
tab=$1
date=$2
freq=$3
text="INSERT INTO $tab ('id', 'name', 'update', 'data')"
text="$text VALUES (NULL, 'cpucurfreq', '$date', '$freq');"
echo "$text"
}
cat -n <<EOF
`func "a" "b b" "c c"`
`func "a" "e e" "f f"`
EOF
exit 0
[guest@localhost sh]$ ./t.sh
1 INSERT INTO a ('id', 'name', 'update', 'data') VALUES (NULL, 'cpucurfreq', 'b b', 'c c');
2 INSERT INTO a ('id', 'name', 'update', 'data') VALUES (NULL, 'cpucurfreq', 'e e', 'f f');
[guest@localhost sh]$
#!/bin/bash
user=${1:-guest}
whoami
sudo -u "$user" whoami
exit 0
[guest@localhost sh]$ ./t.sh guest
guest
guest
[guest@localhost sh]$ ./t.sh apache
guest
apache
[guest@localhost sh]$