Click here to Skip to main content
15,917,176 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Restrict window space for child process Pin
paulb23-Oct-03 12:56
paulb23-Oct-03 12:56 
Generalabout voice chat between a client and a server Pin
yingkou22-Oct-03 18:55
yingkou22-Oct-03 18:55 
Generalsimple questions.... Pin
joshfl22-Oct-03 18:09
joshfl22-Oct-03 18:09 
GeneralRe: simple questions.... Pin
abc87622-Oct-03 20:54
abc87622-Oct-03 20:54 
GeneralRe: simple questions.... Pin
David Crow23-Oct-03 4:03
David Crow23-Oct-03 4:03 
GeneralRe: simple questions.... Pin
joshfl23-Oct-03 6:05
joshfl23-Oct-03 6:05 
GeneralGet printer status by parallel port programming Pin
Rapo Lee22-Oct-03 17:48
Rapo Lee22-Oct-03 17:48 
GeneralHelp with a C bug Pin
Sirrius22-Oct-03 16:36
Sirrius22-Oct-03 16:36 
I have some code here that is supposed to swap bytes in a word. For some reason it has a bug in it in the ByteSwap2 function or the ByteSwap_c function. It's getting very frustrating and time is running out. Can anyone help me..?

The main is on the bottom of the code.
Thanks.
B

void ByteSwap2_c(int n, short *a)
{
  
  int i;
  
  for (i=0; i<n; ++i) {
     
    short int tmp=a[i];
    short int pmt;
    ((char*)(&pmt))[1]=((char*)(&tmp))[0];
    ((char*)(&pmt))[0]=((char*)(&tmp))[1]; 
	//printf("%x\n",a[i]);
    a[i]=pmt;
  }
}





#include "stdio.h"

void ByteSwap2_c(int n, short int *a);
void ByteSwap2_asm(int n, short int *a);

void ByteSwap2(int n, short int *a)
{
  int i;
  short *b = (char *) malloc ( n * sizeof(short int));
  for (i=0; i<n; ++i) 
	  b[i]=a[i];

 //ByteSwap2_asm(n,a);
 ByteSwap2_c(n,b);

  for (i=0; i<n; ++i) {
    if (a[i] != b[i]) {
		
      printf("a[%d] (0x%04X) != b[%d] (0x%04X)\n",i,a[i],i,b[i]);
      exit(1);
    }
  }

  free(b);
}

void test2(int n, short int *a, short int *b)
{
  int i;
  ByteSwap2(n,a);
  for (i=0; i<n; ++i) {
    if (a[i] != b[i]) {
      printf("a[%d] (0x%04X) != b[%d] (0x%04X)\n",i,a[i],i,b[i]);
      exit(1);
    }
  }
}

int main()
{
  static short int a[4]={0x0304, 0x8999, 0xef12, 0x5678};
  static short int b[4]={0x0403, 0x9989, 0x12ef, 0x7856};

  test2(4,a,b);

  printf("all tests pass\n");
}

GeneralRe: Help with a C bug Pin
Anthony_Yio22-Oct-03 22:00
Anthony_Yio22-Oct-03 22:00 
GeneralRe: Help with a C bug Pin
David Crow23-Oct-03 4:06
David Crow23-Oct-03 4:06 
QuestionHow to make toolbar always active? Pin
Hailiang Yu22-Oct-03 16:17
Hailiang Yu22-Oct-03 16:17 
AnswerRe: How to make toolbar always active? Pin
Anthony_Yio22-Oct-03 21:43
Anthony_Yio22-Oct-03 21:43 
GeneralRe: How to make toolbar always active? Pin
Hailiang Yu22-Oct-03 23:42
Hailiang Yu22-Oct-03 23:42 
GeneralRe: How to make toolbar always active? Pin
Anthony_Yio27-Oct-03 16:13
Anthony_Yio27-Oct-03 16:13 
Generalrefreshing windows Pin
coda_x22-Oct-03 15:33
coda_x22-Oct-03 15:33 
GeneralRe: refreshing windows Pin
Atif Mushtaq22-Oct-03 21:58
Atif Mushtaq22-Oct-03 21:58 
GeneralRe: refreshing windows Pin
coda_x23-Oct-03 15:54
coda_x23-Oct-03 15:54 
GeneralHelp with random numbers... Pin
Snyp22-Oct-03 15:19
Snyp22-Oct-03 15:19 
GeneralRe: Help with random numbers... Pin
d00_ape23-Oct-03 1:50
sussd00_ape23-Oct-03 1:50 
GeneralRe: Help with random numbers... Pin
David Crow23-Oct-03 4:10
David Crow23-Oct-03 4:10 
QuestionI still have no idea how do we benefit from rescursion? Pin
Link260022-Oct-03 12:55
Link260022-Oct-03 12:55 
AnswerRe: I still have no idea how do we benefit from rescursion? Pin
Michael Dunn22-Oct-03 14:17
sitebuilderMichael Dunn22-Oct-03 14:17 
GeneralRe: I still have no idea how do we benefit from rescursion? Pin
Link260022-Oct-03 14:31
Link260022-Oct-03 14:31 
GeneralRe: I still have no idea how do we benefit from rescursion? Pin
Ravi Bhavnani22-Oct-03 21:52
professionalRavi Bhavnani22-Oct-03 21:52 
GeneralRe: I still have no idea how do we benefit from rescursion? Pin
David Crow23-Oct-03 6:17
David Crow23-Oct-03 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.