-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANA.c
84 lines (71 loc) · 1.5 KB
/
ANA.c
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
#include<stdio.h>
#define MAXWORDLENGTH 30
#define DEPTH 2
int word(char *pointer);
int analize(char *pointer1, char *pointer2, int cantidad1, int cantidad2);
//probando gitttttttt e_e, Y AHORA Q PASA?????
int main (void)
{
int result;
char wordmatrix[DEPTH][MAXWORDLENGTH];
char *pointer1,*pointer2;
pointer1=&wordmatrix[0][0];
pointer2=&wordmatrix[1][0];
result=0; //probando cosas gittt
if(word(pointer1)>MAXWORDLENGTH)
{
printf("Invalid length of text\n");
printf("The program will stop running\n");
return 0;
}
//asdasjdasldjasdj borre todo jajajajaja (?
//int cantidad1=countchar(pointer1);
//int cantidad2=countchar(pointer2);
result=analize(pointer1, pointer2, 4, 4); // faltan cantidad1 y cantidad2
if(result==1)
{
printf("Congrats, is an anagram(?)\n");
}
else
{
printf("SORRY, those words are not anagrams\n" );
}
system("./ANA.out");
return 0;
}
int analize(char *pointer1, char *pointer2, int cantidad1, int cantidad2)
{ char *punt;
punt=pointer1;
int i,x,z;
for(i=0,z=0;i<cantidad2;pointer2++,z=0,i++)
{punt=pointer1;
for(x=0;x<cantidad1;x++,punt++)
{
if((*punt)==(*pointer2))
{
*punt=0;
z++;
}
}
if (z==0)
{
return 0;
}
}
return 1;
}
int word(char *pointer) // estamos pasandole un puntero a la funcion
{
int i=0; // Contador para conocer la longitud del texto.
char *pointer2;
pointer2=pointer;
char word = getchar();
while (word != '\n')
{
*pointer2=word;
pointer2++;
i++;
word = getchar();
}
return i;
}