Skip to content

Commit 853102d

Browse files
committed
Update 24/02 14:15
1 parent a7dd0f0 commit 853102d

File tree

3 files changed

+61
-40
lines changed

3 files changed

+61
-40
lines changed

Examen/examen.c

+17-39
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,20 @@
1616

1717
#define TAM 11
1818

19+
typedef int num;
20+
21+
typedef struct {
22+
char strA[TAM];
23+
char strB[TAM];
24+
char strC[TAM];
25+
} reg;
26+
1927
main(){
20-
struct reg {
21-
char strA[TAM];
22-
char strB[TAM];
23-
char strC[TAM];
24-
};
25-
2628
FILE *fich;
2729

28-
29-
struct reg regUser = {"", "", ""};
30-
char userStr[TAM], cmpBuffer[TAM];
31-
int strCount = 0, i = 0;
30+
reg regUser = {"", "", ""};
31+
char userStr[TAM] = "";
32+
num strCount = 0, i = 0;
3233

3334
setlocale(LC_ALL, "Spanish");
3435

@@ -58,40 +59,17 @@ main(){
5859
printf("Cadena a buscar (máx. %d %s): ", TAM-1, TAM-1 != 1 ? "caracteres" : "caracter");
5960
gets(userStr);
6061

61-
strcpy(cmpBuffer, userStr);
62-
63-
for(i=0; i<strlen(cmpBuffer); i++){
64-
if(!isupper(cmpBuffer[i]))
65-
cmpBuffer[i]= toupper(cmpBuffer[i]);
66-
}
67-
62+
strCount = 0;
6863
fread(&regUser, sizeof(regUser), 1, fich);
69-
while(!feof(fich)){
70-
for(i=0; i<strlen(regUser.strA); i++){
71-
if(!isupper(regUser.strA[i]))
72-
regUser.strA[i] = toupper(regUser.strA[i]);
73-
}
74-
75-
strCount = !strcmp(regUser.strA, cmpBuffer) ? strCount+1 : strCount;
76-
77-
for(i=0; i<strlen(regUser.strB); i++){
78-
if(!isupper(regUser.strB[i]))
79-
regUser.strB[i] = toupper(regUser.strB[i]);
80-
}
81-
82-
strCount = !strcmp(regUser.strB, cmpBuffer) ? strCount+1 : strCount;
83-
84-
for(i=0; i<strlen(regUser.strC); i++){
85-
if(!isupper(regUser.strC[i]))
86-
regUser.strC[i] = toupper(regUser.strC[i]);
87-
}
88-
89-
strCount = !strcmp(regUser.strC, cmpBuffer) ? strCount+1 : strCount;
64+
while(!feof(fich)){
65+
strCount = !stricmp(regUser.strA, userStr) ? strCount+1 : strCount;
66+
strCount = !stricmp(regUser.strB, userStr) ? strCount+1 : strCount;
67+
strCount = !stricmp(regUser.strC, userStr) ? strCount+1 : strCount;
9068

9169
fread(&regUser, sizeof(regUser), 1, fich);
9270
}
9371

94-
printf("La cadena %s ha sido encontrada %d %s.", userStr, strCount, strCount != 1 ? "veces" : "vez");
72+
printf("La cadena \"%s\" ha sido encontrada %d %s.", userStr, strCount, strCount != 1 ? "veces" : "vez");
9573

9674
fclose(fich);
9775

Manejo de fechas/strtime.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
#include <stdio.h>
6+
#include <stdlib.h>
67
#include <time.h>
78
#include <locale.h>
89

@@ -15,8 +16,9 @@ main(){
1516
while(1){
1617
time(&now);
1718
strftime(buffer, TAM, "%H:%M:%S", localtime(&now));
19+
printf("%s\n", buffer);
20+
system("timeout 1 > nul");
1821
system("cls");
19-
printf("%s", buffer);
2022
}
2123

2224
return 0;

Manejo de fechas/timefrom.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <time.h>
4+
#include <locale.h>
5+
6+
#define TAM 20
7+
8+
main(){
9+
time_t start = 0, now = 0, mod = 0;
10+
int s = 0, m = 0, h = 0;
11+
char timeS[TAM] = "", timeN[TAM] = "";
12+
struct tm dateN;
13+
14+
time(&start);
15+
strftime(timeS, TAM, "%H h %M m %S s", localtime(&start));
16+
17+
18+
19+
while(1){
20+
time(&now);
21+
mod = now - start;
22+
s = (int)mod;
23+
if (s >= 60){
24+
m = s / 60;
25+
s = s % 60;
26+
if (m >= 60){
27+
h = h / 60;
28+
m = m % 60;
29+
}
30+
}
31+
32+
strftime(timeN, TAM, "%M m %S s", localtime(&mod));
33+
34+
printf("Empezo a las %s.\n", timeS);
35+
printf("Transcurrio %d h %d m %d s\n", h, m, s);
36+
system("timeout 1 > nul");
37+
system("cls");
38+
}
39+
40+
return 0;
41+
}

0 commit comments

Comments
 (0)