sprintf problems

Discussion in 'C' started by susmatt, Nov 17, 2007.

  1. susmatt

    susmatt New Member

    Joined:
    Nov 17, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Nov 17, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I don't understand the lines like
    Code:
    % my x[k] is a structure with .re and .im parts
     
  3. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Telling us how you declared 'str' as well would be a bonus.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice