illegal use of pointer error

Discussion in 'C' started by pjc88, Jul 28, 2012.

  1. pjc88

    pjc88 New Member

    Joined:
    Jul 28, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    this is my question: Σ sum of terms from i=2 to 10, the equation is (n+2)/n!.
    I am using recursion for the sum and fact functions.
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    int sum(int);
    long int fact(int);
    
    int main()
    {
    int n;
    long int s;
    clrscr();
    
    printf("Enter Number:");
    scanf("%d\n"&n);
    s=sum(n);
    printf("Sum of %d is =%d"n,s);
    getch();
    
    }
    int fact(int i)
    {
    if (i<=0) return 1;
    else return (i*fact(i-1));
    }
    int sum(int c)
    {
    if(c<2) return 0;
    if else (c>10) return 0;
    else return ((c+2)/fact©);
    }
    
    I am getting the following error:
    Illegal use of pointer in the line "scanf("%d\n"&n);" at n

    what did i do wrong?
     
  2. hobbyist

    hobbyist New Member

    Joined:
    Jan 7, 2012
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    0
    If it's not a typo, the printfs and scanfs are missing commas. having "%d\n" in scanf is kinda hokie too.

    Code:
    scanf("%d\n"&n);
    scanf("%d\n", &n);
    the fact function's return type is mismatched in the proto and definition. if this is some sort of convergence thing, integer division will probably return 0 before you'd want it to. maybe cast that printf sum result as a float or double??
     
  3. 7900142

    7900142 New Member

    Joined:
    Jan 12, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Free lance software developer, an instructor and a
    Location:
    Philippines
    I agree to the post of hobbyist, and also just to make everything clear and safe do the following instead:
    PHP:
     scanf("%d",&n);
     
    printf("\n");
    Due to some reason, if we are using the '\n' inside scanf function, things gets complicated and sometimes gives errors such as the one that you have encountered.
     
  4. skr1986

    skr1986 New Member

    Joined:
    Aug 2, 2012
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    0
    hai,
    Why do we need a '\n' for scanf???
    when u are enter a number, character or string at the end we will
    press enter which give us a newline character so i think there is
    no point in giving '\n' in scanf.
    Regards
    SHIBIN K REEN
     

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