I get a blinking cursor instead of output when running this C program in Ubuntu

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












Here's my code for finding the distance between two points. My assignment makes it mandatory to make use of functions, hence a separate one for finding the distance. I don't get any syntax errors but only a blinking cursor when I execute the code. I'm a beginner in C.



My code:



#include <stdio.h>
#include <math.h>
#include <stdlib.h>

float distance(float *x1, float *y1, float *x2, float *y2);

int main()
printf("Input coordinates as x1,y1,x2,y2:n");
float x1,y1,x2,y2;
scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);

printf("Coordinates are : (%f,%f) and (%f,%f)n",x1,y1,x2,y2);
printf("%f",distance (&x1,&y1,&x2,&y2));
return 0;


float distance(float *x1, float *y1, float *x2, float *y2)

float d= sqrt(pow((*x1-*x2),2)+pow((*y1-*y2),2));
printf("%f", d);
return d;



while compiling:
gcc -o 1 1.c -lm
output:



Input coordinates as x1,y1,x2,y2:
1 2 3 4


That's it. The cursor keeps blinking without providing any output.



Also, I tried putting in print statements at various points. Any print after the scanf doesn't work.










share|improve this question









New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Did you press enter after writing 1 2 3 4?
    – pqnet
    26 mins ago










  • Yes I did. Simply goes to a new line
    – Sayantan Mukherjee
    22 mins ago














up vote
3
down vote

favorite












Here's my code for finding the distance between two points. My assignment makes it mandatory to make use of functions, hence a separate one for finding the distance. I don't get any syntax errors but only a blinking cursor when I execute the code. I'm a beginner in C.



My code:



#include <stdio.h>
#include <math.h>
#include <stdlib.h>

float distance(float *x1, float *y1, float *x2, float *y2);

int main()
printf("Input coordinates as x1,y1,x2,y2:n");
float x1,y1,x2,y2;
scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);

printf("Coordinates are : (%f,%f) and (%f,%f)n",x1,y1,x2,y2);
printf("%f",distance (&x1,&y1,&x2,&y2));
return 0;


float distance(float *x1, float *y1, float *x2, float *y2)

float d= sqrt(pow((*x1-*x2),2)+pow((*y1-*y2),2));
printf("%f", d);
return d;



while compiling:
gcc -o 1 1.c -lm
output:



Input coordinates as x1,y1,x2,y2:
1 2 3 4


That's it. The cursor keeps blinking without providing any output.



Also, I tried putting in print statements at various points. Any print after the scanf doesn't work.










share|improve this question









New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Did you press enter after writing 1 2 3 4?
    – pqnet
    26 mins ago










  • Yes I did. Simply goes to a new line
    – Sayantan Mukherjee
    22 mins ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











Here's my code for finding the distance between two points. My assignment makes it mandatory to make use of functions, hence a separate one for finding the distance. I don't get any syntax errors but only a blinking cursor when I execute the code. I'm a beginner in C.



My code:



#include <stdio.h>
#include <math.h>
#include <stdlib.h>

float distance(float *x1, float *y1, float *x2, float *y2);

int main()
printf("Input coordinates as x1,y1,x2,y2:n");
float x1,y1,x2,y2;
scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);

printf("Coordinates are : (%f,%f) and (%f,%f)n",x1,y1,x2,y2);
printf("%f",distance (&x1,&y1,&x2,&y2));
return 0;


float distance(float *x1, float *y1, float *x2, float *y2)

float d= sqrt(pow((*x1-*x2),2)+pow((*y1-*y2),2));
printf("%f", d);
return d;



while compiling:
gcc -o 1 1.c -lm
output:



Input coordinates as x1,y1,x2,y2:
1 2 3 4


That's it. The cursor keeps blinking without providing any output.



Also, I tried putting in print statements at various points. Any print after the scanf doesn't work.










share|improve this question









New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Here's my code for finding the distance between two points. My assignment makes it mandatory to make use of functions, hence a separate one for finding the distance. I don't get any syntax errors but only a blinking cursor when I execute the code. I'm a beginner in C.



My code:



#include <stdio.h>
#include <math.h>
#include <stdlib.h>

float distance(float *x1, float *y1, float *x2, float *y2);

int main()
printf("Input coordinates as x1,y1,x2,y2:n");
float x1,y1,x2,y2;
scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);

printf("Coordinates are : (%f,%f) and (%f,%f)n",x1,y1,x2,y2);
printf("%f",distance (&x1,&y1,&x2,&y2));
return 0;


float distance(float *x1, float *y1, float *x2, float *y2)

float d= sqrt(pow((*x1-*x2),2)+pow((*y1-*y2),2));
printf("%f", d);
return d;



while compiling:
gcc -o 1 1.c -lm
output:



Input coordinates as x1,y1,x2,y2:
1 2 3 4


That's it. The cursor keeps blinking without providing any output.



Also, I tried putting in print statements at various points. Any print after the scanf doesn't work.







printing compiling gcc c






share|improve this question









New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 20 mins ago









Zanna

48.5k13120230




48.5k13120230






New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 3 hours ago









Sayantan Mukherjee

162




162




New contributor




Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Sayantan Mukherjee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Did you press enter after writing 1 2 3 4?
    – pqnet
    26 mins ago










  • Yes I did. Simply goes to a new line
    – Sayantan Mukherjee
    22 mins ago
















  • Did you press enter after writing 1 2 3 4?
    – pqnet
    26 mins ago










  • Yes I did. Simply goes to a new line
    – Sayantan Mukherjee
    22 mins ago















Did you press enter after writing 1 2 3 4?
– pqnet
26 mins ago




Did you press enter after writing 1 2 3 4?
– pqnet
26 mins ago












Yes I did. Simply goes to a new line
– Sayantan Mukherjee
22 mins ago




Yes I did. Simply goes to a new line
– Sayantan Mukherjee
22 mins ago










2 Answers
2






active

oldest

votes

















up vote
5
down vote













The question you are asking is not specific to Ubuntu but to C programming. I would suggest you ask such questions at Stackoverflow -- it's for your own benefit, as well, since you'll reach a different audience.



Anyway, you should read up on the scanf () function as it is trying to match what you're typing in on the keyboard. That includes any spaces, newlines, etc. that you have in the formatting string. Then, you also need to end your input into standard in with the "Return key".



For your problem, change:



scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);


to:



scanf("%f %f %f %f",&x1,&y1,&x2,&y2);


(Remove the space at the end of the formatting string.) And then it should work as expected.



Personally, I've always used scanf to read a value at a time. As shown in the example here. I admit that this was just my way of avoiding the problem you're seeing.






share|improve this answer




















  • Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
    – Sergiy Kolodyazhnyy
    1 hour ago










  • Thanks, solved my problem.
    – Sayantan Mukherjee
    21 mins ago

















up vote
2
down vote













Two things:




  1. gcc is for compiling, not running code.


  2. -o flag specifies the name of new file to create. Because you run gcc and there's no errors, it means it compiled the C code 1.c into a file 1 that you specified with -o flag. Thus, you can just run ./1 in terminal.

Note that using numbers for executable names is bad practice and also bad naming convention. Use gcc -o distance -lm 1.c instead, and run ./distance in terminal



Note also that because we give bare name of the file, it will create executable in current working directory. That's why you need ./






share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "89"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1085985%2fi-get-a-blinking-cursor-instead-of-output-when-running-this-c-program-in-ubuntu%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    The question you are asking is not specific to Ubuntu but to C programming. I would suggest you ask such questions at Stackoverflow -- it's for your own benefit, as well, since you'll reach a different audience.



    Anyway, you should read up on the scanf () function as it is trying to match what you're typing in on the keyboard. That includes any spaces, newlines, etc. that you have in the formatting string. Then, you also need to end your input into standard in with the "Return key".



    For your problem, change:



    scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);


    to:



    scanf("%f %f %f %f",&x1,&y1,&x2,&y2);


    (Remove the space at the end of the formatting string.) And then it should work as expected.



    Personally, I've always used scanf to read a value at a time. As shown in the example here. I admit that this was just my way of avoiding the problem you're seeing.






    share|improve this answer




















    • Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
      – Sergiy Kolodyazhnyy
      1 hour ago










    • Thanks, solved my problem.
      – Sayantan Mukherjee
      21 mins ago














    up vote
    5
    down vote













    The question you are asking is not specific to Ubuntu but to C programming. I would suggest you ask such questions at Stackoverflow -- it's for your own benefit, as well, since you'll reach a different audience.



    Anyway, you should read up on the scanf () function as it is trying to match what you're typing in on the keyboard. That includes any spaces, newlines, etc. that you have in the formatting string. Then, you also need to end your input into standard in with the "Return key".



    For your problem, change:



    scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);


    to:



    scanf("%f %f %f %f",&x1,&y1,&x2,&y2);


    (Remove the space at the end of the formatting string.) And then it should work as expected.



    Personally, I've always used scanf to read a value at a time. As shown in the example here. I admit that this was just my way of avoiding the problem you're seeing.






    share|improve this answer




















    • Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
      – Sergiy Kolodyazhnyy
      1 hour ago










    • Thanks, solved my problem.
      – Sayantan Mukherjee
      21 mins ago












    up vote
    5
    down vote










    up vote
    5
    down vote









    The question you are asking is not specific to Ubuntu but to C programming. I would suggest you ask such questions at Stackoverflow -- it's for your own benefit, as well, since you'll reach a different audience.



    Anyway, you should read up on the scanf () function as it is trying to match what you're typing in on the keyboard. That includes any spaces, newlines, etc. that you have in the formatting string. Then, you also need to end your input into standard in with the "Return key".



    For your problem, change:



    scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);


    to:



    scanf("%f %f %f %f",&x1,&y1,&x2,&y2);


    (Remove the space at the end of the formatting string.) And then it should work as expected.



    Personally, I've always used scanf to read a value at a time. As shown in the example here. I admit that this was just my way of avoiding the problem you're seeing.






    share|improve this answer












    The question you are asking is not specific to Ubuntu but to C programming. I would suggest you ask such questions at Stackoverflow -- it's for your own benefit, as well, since you'll reach a different audience.



    Anyway, you should read up on the scanf () function as it is trying to match what you're typing in on the keyboard. That includes any spaces, newlines, etc. that you have in the formatting string. Then, you also need to end your input into standard in with the "Return key".



    For your problem, change:



    scanf("%f %f %f %f ",&x1,&y1,&x2,&y2);


    to:



    scanf("%f %f %f %f",&x1,&y1,&x2,&y2);


    (Remove the space at the end of the formatting string.) And then it should work as expected.



    Personally, I've always used scanf to read a value at a time. As shown in the example here. I admit that this was just my way of avoiding the problem you're seeing.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered 2 hours ago









    Ray

    788520




    788520











    • Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
      – Sergiy Kolodyazhnyy
      1 hour ago










    • Thanks, solved my problem.
      – Sayantan Mukherjee
      21 mins ago
















    • Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
      – Sergiy Kolodyazhnyy
      1 hour ago










    • Thanks, solved my problem.
      – Sayantan Mukherjee
      21 mins ago















    Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
    – Sergiy Kolodyazhnyy
    1 hour ago




    Another better idea would be to use argv positional parameters instead of scanf altogether. But that's another topic entirely.
    – Sergiy Kolodyazhnyy
    1 hour ago












    Thanks, solved my problem.
    – Sayantan Mukherjee
    21 mins ago




    Thanks, solved my problem.
    – Sayantan Mukherjee
    21 mins ago












    up vote
    2
    down vote













    Two things:




    1. gcc is for compiling, not running code.


    2. -o flag specifies the name of new file to create. Because you run gcc and there's no errors, it means it compiled the C code 1.c into a file 1 that you specified with -o flag. Thus, you can just run ./1 in terminal.

    Note that using numbers for executable names is bad practice and also bad naming convention. Use gcc -o distance -lm 1.c instead, and run ./distance in terminal



    Note also that because we give bare name of the file, it will create executable in current working directory. That's why you need ./






    share|improve this answer
























      up vote
      2
      down vote













      Two things:




      1. gcc is for compiling, not running code.


      2. -o flag specifies the name of new file to create. Because you run gcc and there's no errors, it means it compiled the C code 1.c into a file 1 that you specified with -o flag. Thus, you can just run ./1 in terminal.

      Note that using numbers for executable names is bad practice and also bad naming convention. Use gcc -o distance -lm 1.c instead, and run ./distance in terminal



      Note also that because we give bare name of the file, it will create executable in current working directory. That's why you need ./






      share|improve this answer






















        up vote
        2
        down vote










        up vote
        2
        down vote









        Two things:




        1. gcc is for compiling, not running code.


        2. -o flag specifies the name of new file to create. Because you run gcc and there's no errors, it means it compiled the C code 1.c into a file 1 that you specified with -o flag. Thus, you can just run ./1 in terminal.

        Note that using numbers for executable names is bad practice and also bad naming convention. Use gcc -o distance -lm 1.c instead, and run ./distance in terminal



        Note also that because we give bare name of the file, it will create executable in current working directory. That's why you need ./






        share|improve this answer












        Two things:




        1. gcc is for compiling, not running code.


        2. -o flag specifies the name of new file to create. Because you run gcc and there's no errors, it means it compiled the C code 1.c into a file 1 that you specified with -o flag. Thus, you can just run ./1 in terminal.

        Note that using numbers for executable names is bad practice and also bad naming convention. Use gcc -o distance -lm 1.c instead, and run ./distance in terminal



        Note also that because we give bare name of the file, it will create executable in current working directory. That's why you need ./







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 hours ago









        Sergiy Kolodyazhnyy

        66.5k9134294




        66.5k9134294




















            Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.












            Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.











            Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1085985%2fi-get-a-blinking-cursor-instead-of-output-when-running-this-c-program-in-ubuntu%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery