Cant stop program & some errors

This is a discussion on Cant stop program & some errors within the C Programming forums, part of the General Programming Boards category; Code: #include<conio.h> main() { float A,B; printf("Input A :");scanf(A); printf("Input B :");scanf(B); if(B==0){ printf("%f, div Q is infinite \n",A); }else{ ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Cant stop program & some errors

    Code:
    #include<conio.h>
    main()
    {
    float A,B;
    printf("Input A :");scanf(A);
    printf("Input B :");scanf(B);
    if(B==0){
    printf("%f, div Q is infinite \n",A);
    }else{
    printf("%f div %f is %f \n", A,B,A/B);}
    }
    getch();
    When i run, it just exit immediately...

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well for starters, that doesn't actually compile. Try compiling with warnings on.


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

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    I've compile that...

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Code:
    scanf(A);
    Perhaps you could read some documentation for that command.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    63
    First off, fix your indentation. It's a pain to have to read code like that. Second off, your scanf() function will do two things: Firstly, the way it is written now, it will not compile. Secondly, should you get it to compile without changing how you pass in the variable, it will result in a segmentation fault.

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    scanf(A) is not going to compile, unless you force it to compile by completely removing the appropriate header, in which case it just won't work.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    Now i got this error after this change
    Warning --- possible use of 'A' before definition in function main

    Code:
    #include<conio.h>
    main()
    {
    float A,B;
    printf("Input A :");scan(A);
    printf("Input B :");scan(B);
    if(B==0){
    printf("%f, div Q is infinite \n",A);
    }else{
    printf("%f div %f is %f \n", A,B,A/B);}
    }
    getch();

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nitediver View Post
    Now i got this error after this change
    Several people have indicated to you that your use of scanf() is incorrect. Before you fix that, nothing else will matter.

    Here is an example of what you want to do:
    Code:
    scanf("%f", &A);
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    i'll try that,
    thx...

  10. #10
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by nitediver View Post
    I've compile that...
    Next time actually read what I wrote. See the part about with warnings on? And no, it won't compile. You can't just have a function call outside of all of your braces (see that bottom line in your first post?).


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

  11. #11
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    thats work!
    thanks...

    but after i input, this block like never exist(like doesnt work)?
    but there was no warning,...
    Code:
    if(B==0){
    printf("%f, div Q is infinite \n",A);
    }else{
    printf("%f div %f is %f \n", A,B,A/B);}
    }
    getch();
    And how to put this, clrscr();
    I do this but give me error...
    Code:
    #include<conio.h>
    main()
    {
    clrscr();
    float A,B;
    printf("Input A :");scanf("%f", &A);
    printf("Input B :");scanf("%f", &B);
    Last edited by nitediver; 10-01-2009 at 09:03 AM.

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nitediver View Post
    thats work!
    thanks...

    but after i input, this block like never exist(like doesnt work)?
    but there was no warning,...
    altho 0 should work, generally do not use == with floating point numbers.

    Try switching your program to use ints temporarily, and post all the code as it is now.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    Sorry2...

    Thats work, but...

    I receive the result i the second time i run it...

  14. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by nitediver View Post
    Sorry2...

    Thats work, but...

    I receive the result i the second time i run it...
    Post the whole program!

    I would not worry about conio.h or clrscr() quite yet. Also, scanf() requires stdio.h -- it may not work properly otherwise.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #15
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    the screenshot...
    With Space
    No Space

    Code:
    #include<stdio.h>
    main()
    {
    char *a,*b;
    int c;
    
    clrscr();
    
    printf("Name   : ");scanf("%s", a);
    printf("Class  : ");scanf("%s", b);
    printf("Number : ");scanf("%d", &c);
    
    printf("Name   : %s\n", a);
    printf("Class  : %s\n", b);
    printf("Number : %d\n", c);
    
    getch();
    }
    1.why i get "null" for the second output?
    2.why if i input more than 5 the number goes wrong?

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

Similar Threads

  1. Can't stop my program at zero (Loan Table)
    By beachsidefl321 in forum C Programming
    Replies: 10
    Last Post: 06-24-2009, 09:14 PM
  2. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  3. Replies: 0
    Last Post: 04-27-2003, 02:04 AM
  4. Average Rainfall Program Errors
    By JamesAnthony23 in forum C Programming
    Replies: 1
    Last Post: 09-11-2002, 10:44 PM
  5. My menu program won't stop looping
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 01-26-2002, 03:30 PM

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