-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkErrors.c
108 lines (84 loc) · 2.29 KB
/
checkErrors.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
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <stdio.h>
#define MAXCHARACTERS 81
#define DEBUG 0
#define DEBUG2 0
#define VALID 1
#define NOTVALID 0
#define EMPTY '.'
int checkIfValid();
void main(void)
{
char twoDimArray[9][9];
char characterArray[81];
int row,col;
int c,numChars, inputRecord,inputCharacters;
int i,j,k;
i = j = k= 0;
row = col = numChars = 0;
inputCharacters = 1;
inputRecord = 1;
int x = checkIfValid(characterArray,twoDimArray, inputCharacters);
}
int checkIfValid(char characterArray[],char twoDimArray[], int inputCharacters)
{
int numChars,c,inputRecord;
int duplicateIndex;
char checkDuplicate[9];
int count = sizeof(checkDuplicate)/sizeof(checkDuplicate[0]);
int i,j;
inputRecord = 1;
numChars = duplicateIndex = c = 0;
while ((c = getchar()) != EOF)
{
printf("%c",c);
/* Load 9 elements into this array and see if there are any duplicates */
checkDuplicate[duplicateIndex] = c;
// printf("check duplicates: at - %d , %c\n",
// duplicateIndex, checkDuplicate[duplicateIndex]);
/* we are going to check for duplicates */
if((duplicateIndex == 8) && (inputRecord == VALID))
{
for (i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
if (checkDuplicate[i] == checkDuplicate[j])
{
if ((checkDuplicate[i] != '.') && (checkDuplicate[j] != '.'))
printf("duplicate found\n");
inputRecord = NOTVALID;
}
}
}
duplicateIndex = 0;
}
else if(duplicateIndex != 8) duplicateIndex++;
if(numChars > MAXCHARACTERS)
{
printf("ERROR: TOO MANY : %d\n",numChars);
numChars = 0;
inputRecord = NOTVALID;
}
if( c == '\n')
{
if((numChars < MAXCHARACTERS) && (inputRecord == VALID))
{
printf("ERROR:TOO FEW : %d\n",numChars);
numChars = 0;
inputRecord = NOTVALID;
}
else if( (numChars == MAXCHARACTERS) && (inputRecord == VALID))
{
printf("OK!!!!\n\n");
numChars = 0;
// inputRecord = VALID;
}
}
else {
/* you want to add characters to elements here */
inputRecord = VALID;
numChars++;
}
}/*end of while loop */
return 1;
}