View previous topic :: View next topic |
Author |
Message |
Rohan
Joined: 05 Jan 2007 Posts: 22
|
Posted: Mon Feb 05, 2007 12:23 pm Post subject: error compiling example |
|
|
Code: | import std.cstream; /* for din.readLine() */
import std.stdio; /* for writef()/writefln() */
int main()
{
char[] name;
writef("Hello friend. Please enter your name: ");
name = din.readLine();
writefln("Thanks, %s",name);
} |
When I compiling it in Elephant I have got error "Function test.main expected to return a value of type int" who can explain this error? |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Mon Feb 05, 2007 1:12 pm Post subject: Re: error compiling example |
|
|
Rohan wrote: | Code: | import std.cstream; /* for din.readLine() */
import std.stdio; /* for writef()/writefln() */
int main()
{
char[] name;
writef("Hello friend. Please enter your name: ");
name = din.readLine();
writefln("Thanks, %s",name);
} |
When I compiling it in Elephant I have got error "Function test.main expected to return a value of type int" who can explain this error? |
You coded : int main()
Which means that you wanted main() to return an int value but you do not have a return statement coded.
Either insert a sreturn statement or change it to: void main() _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
Rohan
Joined: 05 Jan 2007 Posts: 22
|
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
|
Back to top |
|
|
Rohan
Joined: 05 Jan 2007 Posts: 22
|
Posted: Wed Feb 07, 2007 10:25 am Post subject: |
|
|
Thanks! Where I can read about format string spec in D?
When need %lf and when other... |
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
|
Back to top |
|
|
Rohan
Joined: 05 Jan 2007 Posts: 22
|
Posted: Sat Apr 07, 2007 8:09 am Post subject: |
|
|
Code: | import std.stdio;
import std.c.stdio;
int main() {
char x, y, q;
writef("Please enter value for x: ");
scanf("%s", & x);
writef("And for y: ");
scanf("%s", & y);
q=x*y;
writefln("result: %s",q);
return 0;
} |
If for example I enter value "a" and "d" I have got error
result: Error: 4invalid UTF-8 sequence |
|
Back to top |
|
|
Rohan
Joined: 05 Jan 2007 Posts: 22
|
Posted: Sun Apr 08, 2007 3:57 am Post subject: |
|
|
And new question
Code: |
import std.stdio;
void main() {
char[] s;
scanf("%s", & s);
writefln("%s", s);
}
|
I've got error "Error: Access Violation" |
|
Back to top |
|
|
Bradley Smith
Joined: 20 Jun 2006 Posts: 60
|
Posted: Sun Apr 08, 2007 3:42 pm Post subject: |
|
|
The C library scanf is used because std.stdio contains the following:
Code: | public import std.c.stdio; |
Therefore, a char* must be passed to scanf. For example,
Code: | import std.stdio;
import std.c.string;
void main(char[][] args)
{
char[1024] buffer;
scanf("%s", buffer.ptr);
char[] input = buffer[0 .. strlen(buffer.ptr)];
writef("%s", input);
} |
|
|
Back to top |
|
|
Rohan
Joined: 05 Jan 2007 Posts: 22
|
Posted: Sat May 05, 2007 5:42 am Post subject: |
|
|
How I can write this C string in D?
|
|
Back to top |
|
|
jcc7
Joined: 22 Feb 2004 Posts: 657 Location: Muskogee, OK, USA
|
Posted: Thu May 10, 2007 12:41 pm Post subject: |
|
|
Rohan wrote: | How I can write this C string in D?
| For those of us that don't know C/C++ (but do know some D), could you explain what you're trying to do?
Are you trying to take a char[] as input, and then store it as an integer or floating-point number? |
|
Back to top |
|
|
davidb
Joined: 03 Apr 2007 Posts: 15
|
Posted: Fri May 11, 2007 3:24 pm Post subject: |
|
|
@Rohan:
Because your previous posts were console i/o related, I assume you meant "cout" instead of "count"?
(And I assume "i" is an int?)
Then you can use
Code: |
int i = 65;
writefln(cast (char) i);
|
which prints 'A' to the console.
@jcc7:
passes "whatever" to the standard Console OUTput stream ("cin >> whatever" is the equivalent,
reads from Standard INput stream and writes the data to "whatever"). "(char)" is an explicit cast,
"cast (char)" in D (although I don't think that was the part you asked after).
david |
|
Back to top |
|
|
Rommie
Joined: 23 Aug 2007 Posts: 6
|
Posted: Thu Aug 23, 2007 3:55 pm Post subject: |
|
|
Rohan wrote: | How I can write this C string in D?
|
writef(cast(char)i);
Rommie |
|
Back to top |
|
|
|