Dear all.
i have a little problem with this code, i use visual studio2005 (ansi
c)
I tremble at the thought that I am feeding a troll, since it is almost
inconceivable that your 'code' could have been written in good faith.
^^^^^^^^^^^^^^^^
That line is, obviously, gibberish.
struct{int integer; char caracter;} realstruct;
^^^^^^^^^^^^^
Here you specify that the 'caracter' member holds a single character.
int main()
{
realstruct.integer = 1;
realstruct.caracter = "someword";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here you try to assign (a pointer to) a literal string into a single
character. This is, rather obviously, a gross error.
At this point, the closing '{' for main has been reached. Every
statement after that brace is outside a function and an obvious error.
printf("%d %c", realstruct.integer, realstruct.caracter)
Leaving off semicolons is not very smart.
system("pause");
The problem is the output of printf realstruct.caracter,
No, the problem is that you don't understand what a char is. Or even
what a C program is. Or even what a programming language is.
i see a
strange character in a command prompt, i tried also to use %s but i
got compiler error.
Be glad your compiler told you that a char is not a string. It didn't
have to.
a) Pay attention to the _contents_ of the diagnostic message, not just
that you have one.
b) Get an elementary C textbook and start reading at the first page.
Programming is not something you do by typing random characters and then
complaining when they don't result in a compilable program.
Compare your code to
[1]
#include <stdio.h>
struct
{
int integer;
char *caracter;
} realstruct;
int main(void)
{
realstruct.integer = 1;
realstruct.caracter = "someword";
printf("%d %s\n", realstruct.integer, realstruct.caracter);
return 0;
}
or
[2]
#include <stdio.h>
struct test_struct
{
int integer;
char *caracter;
};
int main(void)
{
struct test_struct realstruct = { 1, "someword" };
printf("%d %s\n", realstruct.integer, realstruct.caracter);
return 0;
}
or, if you have C99-style initializations, so you need know only the
relevant member names
[3]
#include <stdio.h>
struct test_struct
{
int integer;
char *caracter;
};
int main(void)
{
struct test_struct realstruct = {.integer = 1,.caracter =
"someword" };
printf("%d %s\n", realstruct.integer, realstruct.caracter);
return 0;
}
If you don't know the relevant string at compile time that you want
caracter to point to, then you have more problems. But, frankly, you
are nowhere close to being able to understand those problems, much less
how to solve them.