Brian said:
Dear clc members,
I am new to C and am posting several messages concerning a large C
program that I am debugging.
I am encountering a "incompatible types in assignment" warning for the
following code during the compile stage:
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
/* removed code */
short int n = 10;
char key[n][6];
If this gets through the compiler, it's either a very
new ("C99") implementation or you're using some compiler-
specific extensions to Standard C. Prior to the C99 edition
of the Standard, array dimensions could only be constants,
and you would have to write `char key[10][6];' instead.
The initialization is pointless, because you're about
to assign new values to `i' in the immediately succeeding
`for' loop.
The limits on `i' are suspect. In C, an array of ten
elements has indices [0], [1], and so on through [9], but
*not* [10]. If this is not yet second nature to you, I
suggest that you are not yet equipped to debug "a large
C program" and you are likely to create more trouble than
you solve. Seriously. Think "novice sword-swallower on
karaoke night."
{
key = ' '; /* incompatible types in assignment */
What is `key'? It is an array of ten elements. What
are those elements? Each is an array of six `char'. In
particular, `key' (for legal values of `i') is an array
of six `char'.
What is the thing on the right-hand side? A single
`char'. (Pedants would say it's an `int' and they'd be right,
but at your present stage of development I think you'd find
the knowledge a distraction. "It's a `char', and damn the
torpedoes.)
Now: Is an array of six somethings the same as a single
something? No, so the attempted assignment makes no sense.
The stuff on the r.h.s. must have the same type as the thing
on the l.h.s., or at least be convertible to it.
As in your other recent difficulty, you're now faced with
trying to figure out what the code's author was trying to
accomplish, after which you need to write a correct expression
of that intention. The original author has said "Gzorgflash"
and it's up to you to discover that he really meant "O for a
Muse of fire!" There is no way any expert or quasi-expert out
here in Usenetland can do this for you given only the original
"Gzorgflash" -- and if the program is as large as you say (and
as badly written as the snippets suggest), I doubt anyone will
undertake the task for free.
{
/* removed code */
}
If there is a similar posting that provides the answer(s), please
point me in the direction. I really do not know what look for in my
search.
Any help is greatly appreciated.
My sincere advice is to hire someone who's C knowledge
exceeds yours. At this point it seems you are a beginner, and
you've been dropped into the deep end without a life jacket.
You are not going to make much progress unaided, and the amount
of aid you require is probably greater than a channel like
Usenet can provide. "Get professional help."