weird error message

Pages: 12
I don't mean to double post but my last post was really long I couldn't stand scrolling any longer and this is a different question. Anyways when I run my program I am getting 6 weird errors that i've never seen before here is one
at this point in file

here is my program.

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
#include <stdio.h>
#include "simpio.h"

char C;
char A[] = {'a','b','c','d','e','f','g','h'}; /* these are set A's values */
char B[] = {'a','c','e','g'}; /* these are set B's values */
char unions();
bool intersection();
bool contain();
int main()
{
    int x;
    for (x=0; x<8; x++)
    {
    printf("%c ", A[x]);
    }
    for (x=0; x<8; x++)
    {
    printf("%c ", B[x]);
    }
      unions(A, B);
      intersection(A, B);
      contain(A, B);
      return 0;
}
char unions()
{
     printf("AUB=");
     int x;
                  for (x=0; x < 10; x++)
                  { 
                    if (A[x] == true || B[x] == true)
                    {
                           C == true; 
                           printf("%c, ", C);
                    }
                  }  
}
bool intersections()
{
     int x, y;
     y=0;
                  for (x=0; x<4; x++)
                  {
                      if (B[x] == A[y])
                      {
                               printf("%c, ", B[x]);
                      }
                      if (B[x] != A[y])
                      {
                               y+=1;
                      }
                  }
}
bool contain()
{
     int x, y; 
    y=0;
                  while (y<4)
                  {
                        for (x=0; x<10; x++)
                        {
                            if (B[y] != A[x])
                            {
                                     printf("\nFALSE");
                                     break; 
                            }
                             if (B[3]==A[x])
                            {
                                           printf("%c\n", B[3]);
                            }
                            if (B[y] == A[x])
                            {
                                     y+=1;
                            }
                           
                        }
                  }
                  getchar();
}

Last edited on
Can you post the full error message?
I believe I already discussed this with you in your last thread.
You cannot check a variable for true/false if it is a character. That has to be part of your errors.
It would also be nice if your functions actually returned something since they all have a boolean return type.
Since you prototyped and defined your functions with no arguments you can't call them with any arguments in main.
Sheesh, a little code proofreading can show you tons of errors off the bat. Try to avoid changing something and then recompiling without first examining your code for things affected by that change.
EDIT: And by the way, this problem is not different from the last one (in fact I would wager that they are virtually identical), and you should not start a new thread just because the scroll wheel's tiring your fingers.
Last edited on
ok so now i'm not getting any errors and I fixed the contain() function but the unions() and intersection() functions aren't working.

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
#include <stdio.h>

bool C;
bool A[] = {'a','b','c','d','e','f','g','h'}; /* these are set A's values */
bool B[] = {'a','c','e','g'}; /* these are set A's values */
char unions(void);
bool intersection(void);
bool contain(void);
int main()
{
    int x;
    for (x=0; x<8; x++)
    {
    printf("%c ", A[x]);
    }
    for (x=0; x<8; x++)
    {
    printf("%c ", B[x]);
    }
      unions();
      intersection();
      contain();
      return 0;
}
char unions(void)
{
     printf("AUB=");
     int x;
                  for (x=0; x < 10; x++)
                  { 
                    if (A[x] == true || B[x] == true)
                    {
                           C == true; 
                           printf("%c, ", C);
                    }
                  }  
}
bool intersection(void)
{
     char ch[];
     int x, y;
     y=0;
                  for (x=0; x<4; x++)
                  {
                      if (B[x] == A[y])
                      {
                               ch[]=B[x];
                               printf("%c ", ch[]);
                      }
                      if (B[x] != A[y])
                      {
                               y+=1;
                      }
                  }
                  
}
bool contain(void)
{
     int x, y; 
    y=0;
                  while (y<4)
                  {
                        for (x=0; x<10; x++)
                        {
                            if (B[y] != A[x])
                            {
                                    C=false;
                            }
                             if (B[0]==A[x] && B[1]==A[x] && B[2]==A[x] && B[3]==A[x])
                            {
                                       C=true;    
                            }
                            if (B[y] == A[x])
                            {
                                     y+=1;
                            }
                           
                        }
                  }
                  if (C==true)
                  {
                              printf("\nTRUE");
                  }
                  else
                  {
                      printf("\nFALSE");
                  }
                  getchar();
}
Last edited on
I've only briefly looked, but this kind of thing might be why:
1
2
3
4
5
                    if (A[x] == true || B[x] == true)
                    {
                           C == true; 
                           printf("%c, ", C);
                    }

In bold you are checking if C is true and then discarding the result. The compiler will probably discard that anyway as it doesn't have any effect on anything else; I guess you want c = true;.
chrisname has marked out the problem line, OP I'm sure you can see what the problem is but I'm going to tell you anyway to save us both some time.
You are, firstly, performing a logic test and not an assignment. The difference between those operators is key to understanding conditionals in C++.
Second, you are saying to the whole array. You want an individual element to be true and not the whole damn thing; if you try to set the whole array to true it's not going to go that way - you get undefined behavior. You do the same thing in contain.
I don't know what you did about those returns because all your functions still have a return type and none of them have any return statements in them.
Finally in intersection you create a char[] with no size. This is doomed to cause errors. Unlike in Java, you cannot just declare an array with no size and leave it that way; you must provide some indicator of its length if it is declared on the stack.
I'm not going to solve any of those problems for you or give you any example code because these are all easy mistakes to figure out. I've shown you where they are and I'll bet I'm missing some; surely you can fix them.
if you try to set the whole array to true it's not going to go that way - you get undefined behavior.
Uhh, no. You get a compiler error.
What are you talking about, though? Where is he setting an entire array?

OP: Why are A and B bool arrays and being assigned characters?
He isn't. But when he used == in the point that chrisname showed, he was probably intending to use =. C=true will result in an error.
Why? C is a scalar.
No as in his array of bools, C[].
Huh? Are you looking at the same declaration I am looking (line 3)?
OK, so it was an array of char. (My fault, I keep getting mixed up.) Same deal though. You still can't assign true to the entire array.
C is a char on my screen. A and B are arrays.

C = true won't result in an error, althought it should probably be casted.

Really, this code needs a full rewrite. I can hardly follow the flow, and I can't understand why so many globals need to be used.

@tummychow,
you're probably getting mixed up for the same reason I am: the flow of this code is confusing.
Last edited on
Whoa, I'm seriously reading badly. I misread the same variable twice.
Still c=true should not be happening. I'm just being blind for some reason.
If I use bool for my arrays what format code would I use to print their values out?
Cycle through the booleans, if it's true print out a cast of the counter in your for loop to char (plus some number, but I don't remember the ASCII codes so I can't say for sure.)
ok... I think i'll go with a char array instead because Im afraid I don't know how to do that. Anyways i almost have my program done except I am a little confused about unions. Am i supposed to combine set A and set B?
That's what a union is.
en.wikipedia.org/wiki/Union_(set_theory)
ok. However, how would i combine set A and set B?
Last edited on
I went over this with you in your last thread and this is why I recommended the use of booleans instead of chars. You're going to have more difficulty doing it the character way because the size of the set is not fixed.
I'm sure that someone on these boards knows what the ascii tables for the alphabetic characters are. Once someone brings that up I can demonstrate to you how to get it done with bools.
Pages: 12