ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i've tried that and it keeps giveing me parse errors
and it's the simplest programme ever
#include <stdio.h)
int main (void)
{
int f;
double c;
printf (Enter number here -> ") ;
scanf (d%", &f);
c = (5.0/9.0)*(f-32) ;
printf("%d = %f\n", f, c) ;
return(0);
}
that's the programme above i wrote it with vi and saved it as blah.c
typed gcc blah.c
and this is what i got back
blah.c: In function 'main' :
blah.c:18: parse error before ')' token
#include <stdio.h>
int main (void)
{
int f;
double c;
printf ("Enter number here -> ") ;
scanf ("%d", &f);
c = (5.0/9.0)*(f-32) ;
printf("%d = %f\n", f, c) ;
return(0);
}
i used the gcc -o execname -c blah.c command (where blah.c is the name of the file)
the command prompt was returned
i then used the ./execname command
and it told me
-bash: ./execname : Permission denied
Excuse me, I found much of your information helpful. But, I keep getting "Segmentation fault" whenever I try to execute my C program. Can you tell me a way to fix this?
Last edited by Inuyasha-kun; 12-06-2003 at 01:25 AM.
#include <stdio.h>
//A is the number to pick the operation
//B and C are the single-precision floating point variables that will be modified
int a;
float b,c;
int main()
{
printf("NCalc 1.0 for Linux%nPick an op%n1:Add%n2:Sub%n3:Mul%n4:Div");
scanf("%d",a);
printf("%nNumber 1:");
scanf("%f",b);
printf("%nNumber 2:");
scanf("%f",c);
if(a == 1);printf("%f+%f=%f",b,c,b+c);
if(a == 2);printf("%f-%f=%f",b,c,b-c);
if(a == 3);printf("%fx%f=%f",b,c,b*c);
if(a == 4);printf("%f/%f=%f",b,c,b/c);
return 0;
}
A very simple calculator program. It compiled with no errors or warnings.
I'd also like to mention that I could never get VC++ to work with "Double"s, back when I mainly ran WinXP.
Last edited by Inuyasha-kun; 12-06-2003 at 01:32 AM.
1: In some of your printfs you have %n, but no parameters following your string. I think what you want in these is \n instead.
2: Your scanfs are passing in a, b, c instead of &a, &b, &c. You need to use a pointer to your variables so that the scanf function can access the memory to fill them in.
Segmentation faults in general are USUALLY because you are touching memory that you have no right touching. In this case you are passing in garbage values to scanf (since your variables aren't initialized), scanf thinks those values are an address to a memory location, (which they aren't), and tries to write memory at that location...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.