Reputation: 179
I have 2 problems:
first problem is that I cant in for (apr = 0; apr < aprno; apr++)
add chars one by one. For example, if I have aprno = 4, after entered A it asks for 4th apr., but It works when I enter AAAA..., also it works with integers only
second problem is char and int comparsion. I know that I cant compare them, but I didnt have found solution how to do it anywhere.
addnoaprons:
system("cls");
printf("Add number of available aprons: ");
scanf("%d", &aprno);
goto addtypeaprons;
addtypeaprons:
if (aprno < 1) goto addnoaprons;
else {
system("cls");
printf("Add types for %d aprons total:", aprno);
for (apr = 0; apr < aprno; apr++)
{
system ("cls");
printf("Aprons total: %d", aprno);
printf("\n\nNo. %d apron type: ", apr + 1);
scanf("%c", &pismapr[apr]);
if (pismapr == 'A') poleapr[apr] = 1;
if (pismapr == 'B') poleapr[apr] = 2;
if (pismapr == 'C') poleapr[apr] = 3;
if (pismapr == 'D') poleapr[apr] = 4;
else goto addtypeaprons;
}
goto showaprons;
}
Upvotes: 2
Views: 229
Reputation: 22663
I have no clue what your first problem is and couldn't really understand what you were asking for that one. Sorry.
Yes, you can compare int
s and char
s, within reason. What you probably don't want to do it to compare the address of a pointer to a char
though.
When I see your question and this:
scanf("%c", &pismapr[apr]);
I can only assume that you mean that pismapr
is an array of char
s or int
s, as I don't see the declaration. So you probably want to switch these:
if (pismapr == 'A')
to:
if (pismapr[apr] == 'A')
But that's assuming the type of pismapr, which we don't know with your snippet.
Lose them. Really. Or tell me why you need them.
system()
Just don't. It's a bad idea, and you probably can do that some other way. If you really want to do this, are you sure you need to do all that with a C program, and not a shell script instead?
Upvotes: 1
Reputation: 81694
pismapr
looks to be an array of char
; you can't compare it directly to a single char
. You need to compare just the array element of interest:
if (pismapr[apr] == 'A') poleapr[apr] = 1;
P.S. I have to tell you, this is some of the weirdest looking C code I've seen in ages. Instead of jumping around with goto
, you should move blocks of code into functions, and then call them in a loop; i.e.,
while (aprno < 1)
aprno = readaprno();
Upvotes: 5