Question on arrays within a struct and sprintf
- From: "aap" <apendse@xxxxxxxxx>
- Date: 27 Jul 2005 12:01:47 -0700
I have the following code
#define MAX 32
struct A
{
char carr[MAX];
int iarr[MAX];
int i;
};
void main()
{
struct A a;
strcpy(a.carr, "a.carr Test1");
char test[MAX];
strcpy(test, "2Test2");
sprintf(test, "%s", &a.carr); //method1
printf("%s\n", test);
sprintf(test, "%s", a.carr); //method2
printf("%s\n", test);
}
I use sprintf twice. In the first case I pass &a.carr as the argument
and in the second caseI pass a.carr as the argument.
In both the cases, the code works just fine.
Why does it not fail in the first case?
How come &a.carr and a.carr both produce identical results?
I apologize if this is already covered in a faq.
Thanks.
.
- Follow-Ups:
- Re: Question on arrays within a struct and sprintf
- From: Keith Thompson
- Re: Question on arrays within a struct and sprintf
- From: Eric Sosman
- Re: Question on arrays within a struct and sprintf
- Prev by Date: Re: Hints on how to migrate from C++ to C
- Next by Date: Re: fexception handling in C
- Previous by thread: Using fgets() within a function returning an error.
- Next by thread: Re: Question on arrays within a struct and sprintf
- Index(es):
Relevant Pages
|