Hi,
I wrote following C program:
#include<stdio.h>
int main(void)
{
char str[20] = “Hello.”;
int num = 353;
for(int i = 1; i <= 10; ++i)
printf("%.10s - %.5d file.\n", str, num);
return 0;
}
How can I write it in Ruby?
Hi,
I wrote following C program:
#include<stdio.h>
int main(void)
{
char str[20] = “Hello.”;
int num = 353;
for(int i = 1; i <= 10; ++i)
printf("%.10s - %.5d file.\n", str, num);
return 0;
}
How can I write it in Ruby?
Adam M. wrote in post #1011423:
Hi,
I wrote following C program:#include<stdio.h>
int main(void)
{
char str[20] = “Hello.”;
int num = 353;
for(int i = 1; i <= 10; ++i)
printf(“%.10s - %.5d file.\n”, str, num);
return 0;
}How can I write it in Ruby?
You’ll find all the info you need at
http://www.ruby-doc.org/docs/ProgrammingRuby/
If you’re already a C programmer, you’ll be able to breeze through this
book very quickly.
Homework problems don’t really belong on this list.
Regards,
Brian.
Hello again,
I tried to find it in this book but I failed. But later found it in doc
Kernel#printf is similar to C printf. This is not homework, but part of
my script (I prepare histogram and learn Perl-like system scripting),
however, you are right I should have googled it more widely.
Thanks for patience and sorry,
Adam M. wrote in post #1011434:
Hello again,
I tried to find it in this book but I failed. But later found it in doc
Kernel#printf is similar to C printf. This is not homework, but part of
my script (I prepare histogram and learn Perl-like system scripting),
however, you are right I should have googled it more widely.
No problem. The C program you gave doesn’t do anything useful - the
values of ‘str’ and ‘num’ don’t change in the loop - so it looked like
an odd thing to want to translate into Ruby.
If you’d asked “how do I make a loop which runs 10 times?” or “how do I
insert the value of a variable into a string?” I’d have been more
inclined to give a straightforward answer.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs