Thread: what is wrong with this code?

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    21

    Lightbulb what is wrong with this code?

    I have written a piece of code to a character and display it a number of times defined by the user, but I got error seems in the scanf statement, can somebody help me? thanks
    Code:
    #include<stdio.h>
    void chline(char z,int x,int y);
    int main(void)
    {
        int x,y;
        printf("ple enter number");
        scanf("%c %d %d",z,&x,&y);
        chline(z,x,y);
        system("pause");
        return 0;
    }
    void chline(char z,int x,int y)
    {
           while(x<=y)
           {
           printf("%c ",z);
           x++;
                      }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You didn't declare a variable called 'z'
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User zouyu1983's Avatar
    Join Date
    Nov 2006
    Location
    Fuzhou University, Fujian, China
    Posts
    35
    "z" is not declareed^_^

  4. #4
    Registered User verbity's Avatar
    Join Date
    Nov 2006
    Posts
    101
    DIDO.....no zzzzzzzzzzzzzzzzzzzzzzzzzz's to be found except in bed....:-)

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You know, if you would actually listen to your compiler, you would know that you didn't declare z...

    I wonder if you'll listen to us.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Registered Luser risby's Avatar
    Join Date
    Jun 2006
    Posts
    72
    Quote Originally Posted by timhxf
    I have written a piece of code to a character and display it a number of times defined by the user, but I got error seems in the scanf statement, can somebody help me? thanks
    Code:
    #include<stdio.h>
    void chline(char z,int x,int y);
    int main(void)
    {
        int x,y;
        char z;
        printf("ple enter number");
        scanf("%c %d %d",&z,&x,&y);
        chline(z,x,y);
        system("pause");
        return 0;
    }
    void chline(char z,int x,int y)
    {
           while(x<=y)
           {
           printf("%c ",z);
           x++;
                      }
    }
    You haven't declared character variable z and you haven't passed the address of that variable as a parameter to scanf(). Otherwise it's OK, but the prompt isn't very helpful to the user about what it is they have to enter.
    ===
    Don't grumble about what you can't have;
    be grateful you don't get what you deserve.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM