sprintf problems

susmatt's Avatar, Join Date: Nov 2007
Newbie Member
I am getting this error (make.exe: *** [goodcode.elf] Error 1), with the following code. . I was hoping someone might be able to help me figure out what might be wrong.one as well. Here is the code:
Code:
float magX[N];
% my x[k] is a structure with .re and .im parts
for(k=0; k<N; k++) {
    magX[k] = sqrt(X[k].re*X[k].re + X[k].im*X[k].im)/N;
}
% error is in one of the following lines of code    
% n is defined as int
for(k=0; k<N; k++) {
    n=sprintf((char *)str,"AD0 %4e",magX[k]);
    serXmit1((unsigned char *)str,n);
}
If I comment out the second for loop, I don't get an error. I am trying to print the magnitude of my FFT result to the screen so that I can double check with Matlab to be sure it is working correctly. I suspect the problem has to do with variable type, but as far as I can tell this code should be correct. I have also tried %4f in place of the %4e with no luck. Any help would be much appreciated. Thanks.

Susan

Last edited by shabbir; 17Nov2007 at 10:13.. Reason: Code block
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I don't understand the lines like
Code:
% my x[k] is a structure with .re and .im parts
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
Telling us how you declared 'str' as well would be a bonus.