S11

//1 //
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

void afiseaza(enum catBreed rasa, char string[100]) {
switch (rasa) {
case 0: strcpy(string, "Birmaneza");
break;
case 1: strcpy(string, "Korat");
break;
case 2: strcpy(string, "Manx");
break;
case 3: strcpy(string, "Ocicat");
break;
case 4: strcpy(string, "Persana");
break;
default: strcpy(string, "Sphinx");
}
return ;
}

int main() {
char string[100];
enum catBreed rasa;
for (rasa = 0; rasa < 6; rasa++) {
afiseaza(rasa, string);
printf("%s\n", string);
}
return 0;
}


//2 //
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

struct Cat {
char nume[100];
enum catBreed rasa;
int varsta;
char culoare[100];
};

void afiseaza_rasa(enum catBreed rasa, char string[100]) {
switch (rasa) {
case 0: strcpy(string, "Birmaneza");
break;
case 1: strcpy(string, "Korat");
break;
case 2: strcpy(string, "Manx");
break;
case 3: strcpy(string, "Ocicat");
break;
case 4: strcpy(string, "Persana");
break;
default: strcpy(string, "Sphinx");
}
return ;
}

struct Cat citesteCat() {
struct Cat motan;

printf("Care este numele pisicii? ");
scanf("%s", motan.nume);
printf("Care este culoarea pisicii? ");
scanf("%s", motan.culoare);
printf("Care este rasa pisicii? Introduceti o cifra cunoscand ca 0=Birmaneza, 1 = Korat, 2 = Manx, 3 = Ocicat, 4 = Persana, 5 = Sphinx. ");
scanf("%d", &motan.rasa);
printf("Care este varsta pisicii? ");
scanf("%d", &motan.varsta);
return motan;
}

void afiseaza(struct Cat motan) {
char string[100];
afiseaza_rasa(motan.rasa, string);
printf("Pisica %s, de rasa %s, are varsta de %d ani si are culoarea %s.\n", motan.nume, string, motan.varsta, motan.culoare);

return;
}

int main() {
struct Cat motan = citesteCat();
afiseaza(motan);

return 0;
}


// 3//
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

struct Cat {
char nume[100];
enum catBreed rasa;
int varsta;
char culoare[100];
};

static struct Cat gCrazyCatLady[10];

struct Cat citesteCat(int i) {
struct Cat motan;
int rasa_numar;

printf("Care este numele pisicii %d ? ", i + 1);
scanf("%s", motan.nume);
printf("Care este culoarea pisicii %d ? ", i + 1);
scanf("%s", motan.culoare);
printf("Care este rasa pisicii %d ? Introduceti o cifra cunoscand ca 0=Birmaneza, 1 = Korat, 2 = Manx, 3 = Ocicat, 4 = Persana, 5 = Sphinx. ", i + 1);
scanf("%d", &rasa_numar);
printf("Care este varsta pisicii %d ? ", i + 1);
scanf("%d", &motan.varsta);

switch (rasa_numar) {
case 0: motan.rasa = BIRMANEZA;
break;
case 1: motan.rasa = KORAT;
break;
case 2: motan.rasa = MANX;
break;
case 3: motan.rasa = OCICAT;
break;
case 4: motan.rasa = PERSANA;
break;
case 5: motan.rasa = SPHINX;
}
return motan;
}

int main() {
int numar_pisici, i, black_counter = 0;
char word[5] = "black";
do {
printf("Cate pisici, de la 1 la 10, are nebuna ? ");
scanf("%d", &numar_pisici);
} while (numar_pisici < 1 || numar_pisici > 10);

for (i = 0; i < numar_pisici; i++) {
gCrazyCatLady[i] = citesteCat(i);
if (strstr(gCrazyCatLady[i].culoare, word) != NULL) {
black_counter++;
}
}

if (black_counter == numar_pisici) {
printf("The crazy cat lady is a witch!\n");
}

return 0;
}


//4//
#include <stdio.h>

union CharAndInt {
int value;
char string[4];
};

int main() {
union CharAndInt var;

var.value = 0x00746163;
printf("%s\n", var.string);
return 0;
}



Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.

You neglected to ask a question, so we have no idea what you want.
closed account (3qD3AqkS)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

void afiseaza(enum catBreed rasa, char string[100]) {
switch (rasa) {
case 0: strcpy(string, "Birmaneza"); 
break;
case 1: strcpy(string, "Korat");
break;
case 2: strcpy(string, "Manx");
break;
case 3: strcpy(string, "Ocicat");
break;
case 4: strcpy(string, "Persana");
break;
default: strcpy(string, "Sphinx");
}
return ;
}

int main() {
char string[100];
enum catBreed rasa;
for (rasa = 0; rasa < 6; rasa++) { 
afiseaza(rasa, string);
printf("%s\n", string);
}
return 0;
}


//2 //
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

struct Cat {
char nume[100];
enum catBreed rasa;
int varsta;
char culoare[100];
};

void afiseaza_rasa(enum catBreed rasa, char string[100]) {
switch (rasa) {
case 0: strcpy(string, "Birmaneza"); 
break;
case 1: strcpy(string, "Korat");
break;
case 2: strcpy(string, "Manx");
break;
case 3: strcpy(string, "Ocicat");
break;
case 4: strcpy(string, "Persana");
break;
default: strcpy(string, "Sphinx");
}
return ;
}

struct Cat citesteCat() {
struct Cat motan;

printf("Care este numele pisicii? ");
scanf("%s", motan.nume);
printf("Care este culoarea pisicii? ");
scanf("%s", motan.culoare);
printf("Care este rasa pisicii? Introduceti o cifra cunoscand ca 0=Birmaneza, 1 = Korat, 2 = Manx, 3 = Ocicat, 4 = Persana, 5 = Sphinx. ");
scanf("%d", &motan.rasa);
printf("Care este varsta pisicii? ");
scanf("%d", &motan.varsta);
return motan;
}

void afiseaza(struct Cat motan) {
char string[100];
afiseaza_rasa(motan.rasa, string);
printf("Pisica %s, de rasa %s, are varsta de %d ani si are culoarea %s.\n", motan.nume, string, motan.varsta, motan.culoare);

return;
}

int main() {
struct Cat motan = citesteCat();
afiseaza(motan);

return 0;
} 


// 3//
#include <stdio.h>
#include <string.h>

enum catBreed {
BIRMANEZA,
KORAT,
MANX,
OCICAT,
PERSANA,
SPHINX
};

struct Cat {
char nume[100];
enum catBreed rasa;
int varsta;
char culoare[100];
};

static struct Cat gCrazyCatLady[10];

struct Cat citesteCat(int i) {
struct Cat motan; 
int rasa_numar;

printf("Care este numele pisicii %d ? ", i + 1);
scanf("%s", motan.nume);
printf("Care este culoarea pisicii %d ? ", i + 1);
scanf("%s", motan.culoare);
printf("Care este rasa pisicii %d ? Introduceti o cifra cunoscand ca 0=Birmaneza, 1 = Korat, 2 = Manx, 3 = Ocicat, 4 = Persana, 5 = Sphinx. ", i + 1);
scanf("%d", &rasa_numar);
printf("Care este varsta pisicii %d ? ", i + 1);
scanf("%d", &motan.varsta);

switch (rasa_numar) {
case 0: motan.rasa = BIRMANEZA; 
break;
case 1: motan.rasa = KORAT;
break;
case 2: motan.rasa = MANX;
break;
case 3: motan.rasa = OCICAT;
break;
case 4: motan.rasa = PERSANA;
break;
case 5: motan.rasa = SPHINX;
}
return motan;
}

int main() {
int numar_pisici, i, black_counter = 0;
char word[5] = "black";
do {
printf("Cate pisici, de la 1 la 10, are nebuna ? ");
scanf("%d", &numar_pisici);
} while (numar_pisici < 1 || numar_pisici > 10);

for (i = 0; i < numar_pisici; i++) {
gCrazyCatLady[i] = citesteCat(i);
if (strstr(gCrazyCatLady[i].culoare, word) != NULL) {
black_counter++;
}
}

if (black_counter == numar_pisici) {
printf("The crazy cat lady is a witch!\n");
}

return 0;
} 


//4//
#include <stdio.h>

union CharAndInt {
int value; 
char string[4];
};

int main() {
union CharAndInt var;

var.value = 0x00746163;
printf("%s\n", var.string);
return 0;
}


for readable codes
@gentlegal there is actual indentation in their original post that was lost when you copypasted it, which is why I ask them to edit their post. I don't mean to discourage your good intentions though ;)
Topic archived. No new replies allowed.