Like Tree2Likes

2nd scanf input problem.

This is a discussion on 2nd scanf input problem. within the C Programming forums, part of the General Programming Boards category; program below not taking input of 2nd scanf ,whats the error? Code: main() { int x,y,z; printf("Enter tghe value of ...

  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    75

    2nd scanf input problem.

    program below not taking input of 2nd scanf ,whats the error?

    Code:
    main()
     {
      int x,y,z;
      
      printf("Enter tghe value of x,y,z : ");
      scanf("%d,%d,%d",&x,&y,&z);
      shift(x,y,z);
      }
      
     shift(int x,int y,int z)
     {
     char b;
      int a;
      a = z;
      z = y;
      y = x;
      x = a;
      printf(" x = %d \n y= %d \n z = %d",x,y,z);
      printf("\nDO you want right circular shift again?(y/n): ");\
      scanf("%c",&b); <=========================problem
     if ( b == 'y')
    {
      shift(x,y,z);
    }
    }

  2. #2
    11DE784A SirPrattlepod's Avatar
    Join Date
    Aug 2013
    Posts
    485
    printf("Enter tghe value of x,y,z : ");
    "the" is spelt wrong

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    thank you,it solved the problem of scanf,however the program is still not running due to "if" part.Can you please point out the error in "if" part of the program.thank you.

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    It seems ok... Can you post your new code please?
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    here is the new code.but its not running.My program name is test ,its giving error on command prompt :- 'test' is not recognized as an internal or external command,operable program or batch file.

    Code:
    #include<stdio.h>
     
     main()
     {
      int x,y,z;
       
      printf("Enter tghe value of x,y,z : ");
      scanf("%d,%d,%d",&x,&y,&z);
      shift(x,y,z);
      }
       
     shift(int x,int y,int z)
     {
     char b;
      int a;
      a = z;
      z = y;
      y = x;
      x = a;
      printf(" x = %d \n y= %d \n z = %d",x,y,z);
      printf("\nDO you want right circular shift again?(y/n): ");
      scanf(" %c",&b);
       if ( b=='y')
      {
      shift(x,y,z);
      }
      }

  7. #7
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    The problem does not come from the code. Try to create a new program and write there your code. If the problem persists, you probably have a configuration problem.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #8
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    Thank you for the quick reply ....(by the way are you sure it runs fine?)

  9. #9
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    Check the article for indent style.

    You forgot to correct your typo in line 7, as SirPrattlepod noted before.

    Moreover, you need a prototype for your function.

    So, either you place your function above main, or you leave the function where it is now, and you place a prototype (a declaration) of the function above main. If you do not get what I said, read this very brief code for the very basics in functions.
    I would also suggest you to specify the return type of your function to void, since it does return anything.
    smokeyangel likes this.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  10. #10
    Registered User
    Join Date
    Mar 2010
    Posts
    535
    Those were exactly the points I was going to make

    The code does run correctly though. That error means that windows can't find a test.exe to run, nothing more, nothing less. Are you in the same directory as test.exe?

  11. #11
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    Quote Originally Posted by smokeyangel View Post
    Those were exactly the points I was going to make
    Sorry that I took your turn.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  12. #12
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    Made some changes and it works really good now.Thanks for the "return" advice.it was dumb of me.
    Bytheway saw your cv,blown away by your achievements dude.Keep it up
    hewre is the code,let me know if you can make it more simpler or compact than this .
    Code:
    #include<stdio.h>
    
    
     main()
     {
      int x,y,z;
       char b;
      printf("Enter the value of x,y,z : ");
      scanf("%d,%d,%d",&x,&y,&z);
      shift(&x,&y,&z);
      printf(" x = %d \n y= %d \n z = %d",x,y,z);
      printf("\nDO you want right circular shift again?(y/n): ");
      scanf(" %c",&b);
       while ( b=='y')
      {
     shift(&x,&y,&z);
     printf(" x = %d \n y= %d \n z = %d",x,y,z);
     printf("\nDO you want right circular shift again?(y/n): ");
     scanf(" %c",&b); 
     }
      return 0;
     }
       
     shift(int *j,int *k,int *l)
     {
     
      int a;
      a = *l;
      *l = *k;
      *k = *j;
      *j = a;
      
     }

  13. #13
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    yup,maybe its some config error,but hey if found another way ...thnx for the reply and help buddy

  14. #14
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,678
    Thank you for the good words of you for the CV.

    I am really glad you made all this changes yourself. Bravo. The last thing I would say, is to read again the Indent Style I posted before. It requires a little effort, but has a very good impact.

    And something you haven't get taught yet.
    We write
    Code:
    int main(void)
    {
           ...
           return 0;
    }
    The reason is that main() is a function too! And as you now know, functions have a return type. main() however is not just a function, it's the MAIN function that every program needs to have. In other words, you must have a main() function.
    So, in order to let others (the system in which your code runs for example), that everything went as expected, you return a code that implies success. 0 is usually used for this.
    However, since many disagree in the numbers which should be used, you can use macros, such as EXIT_SUCCESS for this purpose. But I think return 0; is just fine.

    As for the configuration problem, try to create a new project and run it.. If this doesn't work, ask here again and someone may know the answer!

    Bravo again for the beautiful transformation you did in your code.
    Last edited by std10093; 09-07-2013 at 09:31 AM.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  15. #15
    Registered User
    Join Date
    Sep 2013
    Posts
    75
    k.Always good to learn new things.And good to have a good fellow coding enthusiast by side.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf and int input problem
    By Penage in forum C Programming
    Replies: 5
    Last Post: 04-14-2010, 06:14 AM
  2. input using scanf()
    By kizyle502 in forum C Programming
    Replies: 5
    Last Post: 09-10-2009, 12:56 AM
  3. Input and Scanf
    By DAaaMan64 in forum C Programming
    Replies: 3
    Last Post: 01-14-2009, 05:56 PM
  4. Problem with scanf input
    By ejpjoker in forum C Programming
    Replies: 4
    Last Post: 04-29-2004, 08:28 PM
  5. help with input and scanf
    By kpw in forum C Programming
    Replies: 9
    Last Post: 08-28-2001, 08:21 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21