B
Bill Cunningham
Is this valid C syntax ?
double=double/int;
I seem to be having trouble here.
Bill
double=double/int;
I seem to be having trouble here.
Bill
Is this valid C syntax ?
double=double/int;
I seem to be having trouble here.
Bill
Bill Cunningham said:Is this valid C syntax ?
I seem to be having trouble here.
No it is not.
$ cat foof.c
int main(void) {
double=double/int;
return 0;}
$ cc -fullwarn foof.c
cc-1040 cc: ERROR File = foof.c, Line = 2
An identifier is expected.
double=double/int;
^
cc-1029 cc: ERROR File = foof.c, Line = 2
An expression is expected at this point.
double=double/int;
^
2 errors detected in the compilation of "foof.c".
'double' is a type name; when it appears at the beginning of
a statement, it is understood as being part of a variable declarator.
As you failed to follow the 'double' with a variable name (or
mix of qualifiers) before the '=', the syntax is invalid.
If you mean more generally is it valid to divide a variable or
value of type double by a variable or value of type int, and
assign the result to a variable of type double, then the answer is Yes,
that is syntactically and semantically permitted; the int would get
promoted to double and the expression would proceed from there.
Is this valid C syntax ?
double=double/int;
I seem to be having trouble here.
------Barry Schwarz said:Post your compilable code so we can all see what the problem is.
Remove del for email
[snip]Walter Roberson said:No it is not.
wrote:Post your compilable code so we can all see what the problem is.Remove del for email
------
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
}
Bill Cunningham said:------Barry Schwarz said:Post your compilable code so we can all see what the problem is.
Remove del for email
#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
}
Bill said:#include <stdio.h>
#include <stdlib.h>
#define _ex exit(EXIT_FAILURE)
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
Everything compiles file. But when I input a number like 21.00 I getWhat is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?
I won't ask this again.
Bert said:On Jul 11, 12:04 pm, "Bill Cunningham" <[email protected]> wrote:int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
Why do I get the feeling that argc != 2 wouldn't work?
You can't write y = x when the comp doesn't know the values stored in
y and x cos they're UNINITIALIZED.
Ya gotta give them something before
you use them elsewhere. Which means that z=y/count doesn't work
either. And I hate people who write y=x instead of y = x.
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
[snip]
What is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?I won't ask this again.
Everything compiles file. But when I input a number like 21.00 I get
this printed to a file.
21.00 0.00 0.00 1
That's not what I envisioned this to print but this at first.
21.00 21.00 21.00 1
Then I am going to probably add a do while loop.
Keith Thompson said:I won't ask this again.
[snip]
Everything compiles file. But when I input a number like 21.00 I getWhat is the actual problem you're having? Are you getting an error or
warning message from your compiler? If so, what *exactly* did it
print? Is the program misbehaving? If so, what *exactly* does it do,
and how does this differ from what you expected?
I won't ask this again.
this printed to a file.
21.00 0.00 0.00 1
That's not what I envisioned this to print but this at first.
21.00 21.00 21.00 1
Then I am going to probably add a do while loop.
Yes but I haven't added the error checking yet as you have yet. I'm notPerhaps you meant something like this:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;
if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;
x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
[/QUOTE]36:19 GMT, "Bill Cunningham"]
wrote:
int main (int argc,char *argv[]) {
if (argc!=2) {
puts("usage error");
_ex;
}
int count=1;
double x,y,z;
y=x;z=y/count; <-----
x=strtod(argv[1],NULL);
FILE *fp;
fp=fopen("s","a");
char *string="%.2f\t%.2f\t%.2f\t%i\n";
fprintf(fp,string,x,y,z,count);
fclose(fp);
return 0;
Neither was I. The above is not even close to a useful program yet, but
it did what I *guessed* that you wanted it to do without violation of the
rules of the C language. Your program was not a proper C program.
Bill Cunningham said:Yes but I haven't added the error checking yet as you have yet. I'm notPerhaps you meant something like this:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int count = 1;
double x = 1,
y,
z;
FILE *fp;
if (argc != 2) {
puts("usage error");
exit(EXIT_FAILURE);
}
y = x;
z = y / count;
x = strtod(argv[1], NULL);
fp = fopen("s", "a");
if (fp) {
fprintf(fp, "%.2f\t%.2f\t%.2f\t%i\n", x, y, z, count);
fclose(fp);
} else {
puts("failed to open file.");
}
return 0;
}
finshed yet.
Bill
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.