I get a blinking cursor instead of output when running this C program in Ubuntu
Clash 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.
printing compiling gcc c
New contributor
add a comment |Â
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.
printing compiling gcc c
New contributor
Did you press enter after writing1 2 3 4
?
â pqnet
26 mins ago
Yes I did. Simply goes to a new line
â Sayantan Mukherjee
22 mins ago
add a comment |Â
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.
printing compiling gcc c
New contributor
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
printing compiling gcc c
New contributor
New contributor
edited 20 mins ago
Zanna
48.5k13120230
48.5k13120230
New contributor
asked 3 hours ago
Sayantan Mukherjee
162
162
New contributor
New contributor
Did you press enter after writing1 2 3 4
?
â pqnet
26 mins ago
Yes I did. Simply goes to a new line
â Sayantan Mukherjee
22 mins ago
add a comment |Â
Did you press enter after writing1 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
add a comment |Â
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.
Another better idea would be to use argv positional parameters instead ofscanf
altogether. But that's another topic entirely.
â Sergiy Kolodyazhnyy
1 hour ago
Thanks, solved my problem.
â Sayantan Mukherjee
21 mins ago
add a comment |Â
up vote
2
down vote
Two things:
gcc
is for compiling, not running code.-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 code1.c
into a file1
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 ./
add a comment |Â
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.
Another better idea would be to use argv positional parameters instead ofscanf
altogether. But that's another topic entirely.
â Sergiy Kolodyazhnyy
1 hour ago
Thanks, solved my problem.
â Sayantan Mukherjee
21 mins ago
add a comment |Â
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.
Another better idea would be to use argv positional parameters instead ofscanf
altogether. But that's another topic entirely.
â Sergiy Kolodyazhnyy
1 hour ago
Thanks, solved my problem.
â Sayantan Mukherjee
21 mins ago
add a comment |Â
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.
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.
answered 2 hours ago
Ray
788520
788520
Another better idea would be to use argv positional parameters instead ofscanf
altogether. But that's another topic entirely.
â Sergiy Kolodyazhnyy
1 hour ago
Thanks, solved my problem.
â Sayantan Mukherjee
21 mins ago
add a comment |Â
Another better idea would be to use argv positional parameters instead ofscanf
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
add a comment |Â
up vote
2
down vote
Two things:
gcc
is for compiling, not running code.-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 code1.c
into a file1
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 ./
add a comment |Â
up vote
2
down vote
Two things:
gcc
is for compiling, not running code.-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 code1.c
into a file1
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 ./
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Two things:
gcc
is for compiling, not running code.-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 code1.c
into a file1
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 ./
Two things:
gcc
is for compiling, not running code.-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 code1.c
into a file1
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 ./
answered 2 hours ago
Sergiy Kolodyazhnyy
66.5k9134294
66.5k9134294
add a comment |Â
add a comment |Â
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.
Sayantan Mukherjee is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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