#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <complex.h>
#undef I
#define j _Imaginary_I
void rbits(short* buf, int nbits)
{
int i;
srand(time(NULL));
for(i = 0; i < nbits; i++)
*(buf + i) = (rand() % 2);
}
int main()
{
int bits, i;
short* input;
input = malloc(sizeof(int) * bits);
if(input == NULL)
{
fprintf(stderr, "Couldn't allocate that much memory!");
return 1;
}
printf("Please enter the number of bits: ");
scanf("%d", &bits);
rbits(input, bits);
for(i = 0; i < bits; i += 2)
{
if(input[i] == 0 && input[i+1] == 0)
{
input[i] = -1;
input[i+1] = -j;
}
else if(input[i] == 0 && input[i+1] == 1)
{
input[i] = -1;
input[i+1] = +j;
}
else if(input[i] == 1 && input[i+1] == 0)
{
input[i] = 1;
input[i+1] = -j;
}
else
{
input[i] = 1;
input[i+1] = +j;
}
}
for(i = 0; i < bits; i++)
printf("%d ", input[i]);
printf("\n");
return 0;
}
My method is not working, while when I run it I get the following errors:
C:\Users\Erkan\Desktop\asdsada.c||In function 'main':|
C:\Users\Erkan\Desktop\asdsada.c|44|error: '_Imaginary_I' undeclared (first use in this function)|
C:\Users\Erkan\Desktop\asdsada.c|44|note: each undeclared identifier is reported only once for each function it appears in|
||=== Build finished: 2 errors, 0 warnings ===|
If someone can offer me a better and working method for imaginary part, I would be glad.
This post has been edited by erkant: 12 March 2012 - 01:46 PM

New Topic/Question
Reply



MultiQuote





|