|
|
Up |
|
|
  |
Author: aarklonaarklon Date: Apr 19, 2008 14:28
Hi,
the following is actually a part of the pattern matching program which
i tried ,memset is not setting the entire integer array with
-1
#include
#include
#include
int main(void)
{
int maxpat[80];
memset(maxpat,-1,80);
for(i=0;i<80;i++)
printf("%%d\t",maxpat[i]);
return EXIT_SUCCESS;
}
but i am getting o/p as
|
| Show full article (1.14Kb) |
|
| | 46 Comments |
|
  |
Author: aarklonaarklon Date: Apr 19, 2008 14:31
sorry I forgot to declare i , but still the o/p is same
#include
#include
#include
int main(void)
{
int maxpat[80],i;
memset(maxpat,-1,80);
for(i=0;i<80;i++)
printf("%%d\t",maxpat[i]);
return EXIT_SUCCESS;
}
|
| |
|
| | no comments |
|
  |
Author: aarklonaarklon Date: Apr 19, 2008 14:32
On Apr 20, 2:28Â am, aark...@ gmail.com wrote:
> Hi,
>
> the following is actually a part of the pattern matching program which
> i tried ,memset is not setting the entire integer array with
> -1
>
> Â #include
> Â #include
> Â #include
>
> Â int main(void)
> Â {
>
> Â Â int maxpat[80];
> Â Â memset(maxpat,-1,80);
>
> Â Â for(i=0;i<80;i++)
> Â Â printf("%%d\t",maxpat[i]);
> ...
|
| Show full article (1.38Kb) |
| no comments |
|
  |
Author: Ian CollinsIan Collins Date: Apr 19, 2008 14:38
> Hi,
>
> the following is actually a part of the pattern matching program which
> i tried ,memset is not setting the entire integer array with
> -1
>
> #include
> #include
> #include
>
> int main(void)
> {
>
> int maxpat[80];
> memset(maxpat,-1,80);
>
You are only setting the first 80 bytes of the the array, not 80 ints.
|
| Show full article (0.42Kb) |
| no comments |
|
  |
Author: BartcBartc Date: Apr 19, 2008 14:45
> Hi,
>
> the following is actually a part of the pattern matching program which
> i tried ,memset is not setting the entire integer array with
> -1
>
> #include
> #include
> #include
>
> int main(void)
> {
>
> int maxpat[80];
> memset(maxpat,-1,80);
You're setting 80 bytes. The array is bigger than that (80*sizeof(int)).
Try:
|
| Show full article (0.54Kb) |
| no comments |
|
  |
Author: Flash GordonFlash Gordon Date: Apr 19, 2008 14:36
> sorry I forgot to declare i , but still the o/p is same
>
> #include
> #include
> #include
>
> int main(void)
> {
> int maxpat[80],i;
> memset(maxpat,-1,80);
Check the definition of memset in your reference book, it sets a
specified number of *bytes*. This also means that having corrected the
error (sizeof *maxpat is your friend) it won't be portable to
implementations using 1s complement or sign-magnitude if you can find
such an implementation.
--
Flash Gordon
|
| |
| no comments |
|
  |
Author: Default UserDefault User Date: Apr 19, 2008 16:43
> Hi,
>
> the following is actually a part of the pattern matching program which
> i tried ,memset is not setting the entire integer array with
> -1
> int maxpat[80];
> memset(maxpat,-1,80);
As the others have pointed out, it sets each byte to the value. There's
almost no way to do what you want with memset(), unless you happen to
be on a machine that had one-byte ints.
To set each int in the array to -1, you need a loop. Better yet,
explain WHY you want to do this. There may be a better construct.
Brian
|
| |
| no comments |
|
  |
Author: Richard TobinRichard Tobin Date: Apr 19, 2008 17:22
>> int maxpat[80];
>> memset(maxpat,-1,80);
>As the others have pointed out, it sets each byte to the value. There's
>almost no way to do what you want with memset(), unless you happen to
>be on a machine that had one-byte ints.
Unless you really on the machines being 2s-complement, which is true
of all general-purpose computers today.
-- Richard
--
:wq
|
| |
| no comments |
|
  |
Author: RichardRichard Date: Apr 19, 2008 20:29
"Default User" yahoo.com> writes:
>> Hi,
>>
>> the following is actually a part of the pattern matching program which
>> i tried ,memset is not setting the entire integer array with
>> -1
>
>> int maxpat[80];
>> memset(maxpat,-1,80);
>
> As the others have pointed out, it sets each byte to the value. There's
> almost no way to do what you want with memset(), unless you happen to
> be on a machine that had one-byte ints.
>
> To set each int in the array to -1, you need a loop. Better yet,
> explain WHY you want to do this. There may be a better construct.
|
| Show full article (0.78Kb) |
| no comments |
|
  |
|
|
  |
Author: CBFalconerCBFalconer Date: Apr 19, 2008 21:06
Richard Tobin wrote:
> Default User yahoo.com> wrote:
>
>>> int maxpat[80];
>>> memset(maxpat,-1,80);
>
>> As the others have pointed out, it sets each byte to the value.
>> There's almost no way to do what you want with memset(), unless
>> you happen to be on a machine that had one-byte ints.
>
> Unless you really on the machines being 2s-complement, which is
> true of all general-purpose computers today.
What's the point of the foolishness, when:
#define MPSIZE 80
#define VALUE -1
int maxpat[MPSIZE], i;
for (i = 0; i < MPSIZE; i++) maxpat[i] = VALUE;
|
| Show full article (1.03Kb) |
| no comments |
|
|
|
|