Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   sprintf problems (http://www.go4expert.com/forums/sprintf-problems-t7346/)

susmatt 17Nov2007 07:46

sprintf problems
 
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

shabbir 17Nov2007 10:14

Re: sprintf problems
 
I don't understand the lines like
Code:

% my x[k] is a structure with .re and .im parts

Salem 17Nov2007 13:48

Re: sprintf problems
 
Telling us how you declared 'str' as well would be a bonus.


All times are GMT +5.5. The time now is 08:58.