•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,598 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,454 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 2210 | Replies: 6
![]() |
•
•
Join Date: Aug 2004
Posts: 76
Reputation:
Rep Power: 5
Solved Threads: 0
Hi everyone, i have just startted programming with C and i have got 3 Questions:
1. How to calculate with decimal numbers in C.
2. How to convert strings into numbers and perform calculations on it.
3. Where to find a book that explains all the header files.
Tahank you very much for answering my Questions.
ps. I left PERL and started with C is it good????.
1. How to calculate with decimal numbers in C.
2. How to convert strings into numbers and perform calculations on it.
3. Where to find a book that explains all the header files.
Tahank you very much for answering my Questions.
ps. I left PERL and started with C is it good????.
•
•
Join Date: Aug 2004
Posts: 10
Reputation:
Rep Power: 5
Solved Threads: 0
Hi, I am a new member 2 I am sorry I can't help with the first and second question but if you like me have no previous experience of programming
I have 2 books (listed below) and this community that I find are great in my oppinion that is......
Book #1 learn to program with C++ by John Smiley ISBN 0-07-222535-1 $29.99 USA..
#2 Microsoft Visual C++.NET step by step v.2003.....That was painful to the walet at £89GBP it came with a compiler and other software I don't know if that is Good or not but it's a start......
Yours Tex.....
I have 2 books (listed below) and this community that I find are great in my oppinion that is......
Book #1 learn to program with C++ by John Smiley ISBN 0-07-222535-1 $29.99 USA..
#2 Microsoft Visual C++.NET step by step v.2003.....That was painful to the walet at £89GBP it came with a compiler and other software I don't know if that is Good or not but it's a start......
Yours Tex.....
•
•
Join Date: Aug 2004
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Originally Posted by Mahen
Hi everyone, i have just startted programming with C and i have got 3 Questions:
1. How to calculate with decimal numbers in C.
2. How to convert strings into numbers and perform calculations on it.
3. Where to find a book that explains all the header files.
Tahank you very much for answering my Questions.
ps. I left PERL and started with C is it good????.
What's up, Mahen? I'm new, too. This is my first post -- hell of an introduction, huh?
Let me try to answer your questions. First off, switching from Perl to C could be good or it could be bad. I strongly recommend C++, however. Despite what people think, they're quite different [at least if you're using the many new features of the language]. But a lot depends on what you want to do.
So, in C++, you can have a string and convert it to numbers. Here's an example:
char * testString = "Hello, Mahen";
int numberofstring = 0;
while ( *testString ) //while string isn't null
{
numberofstring = static_cast< int >( *testString );
//Do what you want with the numeric value, etc.
testString++; //Move the pointer to the next character.
}
You can also use the STL string type to make it even easier, but this looks more C-esque, so I decided to use that.
Your first question I don't understand. Can you be more specific? Do you just want to do arithmetic operations on decimal numbers or something else?
Let me know.
•
•
Join Date: Aug 2004
Posts: 76
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
•
•
Originally Posted by The Code Poet
What's up, Mahen? I'm new, too. This is my first post -- hell of an introduction, huh?Let me try to answer your questions.
First off, switching from Perl to C could be good or it could be bad. I strongly recommend C++, however. Despite what people think, they're quite different [at least if you're using the many new features of the language]. But a lot depends on what you want to do.
So, in C++, you can have a string and convert it to numbers. Here's an example:
char * testString = "Hello, Mahen";
int numberofstring = 0;
while ( *testString ) //while string isn't null
{
numberofstring = static_cast< int >( *testString );
//Do what you want with the numeric value, etc.
testString++; //Move the pointer to the next character.
}
You can also use the STL string type to make it even easier, but this looks more C-esque, so I decided to use that.
Your first question I don't understand. Can you be more specific? Do you just want to do arithmetic operations on decimal numbers or something else?
Let me know.
Thank you very much for replying my question, let me clear things up, for the first question, yes i only want to perform arithmetic operations on the decimal numbers. Thanks
ps. Found it easier to learn C after learning PERL, but PERL is more easy and democratic than C. :p
•
•
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation:
Rep Power: 5
Solved Threads: 10
You want to convert "123" into the integer 123?
C and C++ have a 'standard library' of routines you can use for this kind of conversion, for example atoi() can be used to convert from ascii to integers:
int n = atoi("123");
n will equal 123. To go the other way, use itoa():
char s[32];
itoa( 123, s, 10 ); // the 10 is for radix 10
There are other functions, so maybe start with these and then look up in 'help' in your compiler for sprintf() and 'data conversion routines'.
C and C++ have a 'standard library' of routines you can use for this kind of conversion, for example atoi() can be used to convert from ascii to integers:
int n = atoi("123");
n will equal 123. To go the other way, use itoa():
char s[32];
itoa( 123, s, 10 ); // the 10 is for radix 10
There are other functions, so maybe start with these and then look up in 'help' in your compiler for sprintf() and 'data conversion routines'.
•
•
Join Date: Aug 2004
Posts: 76
Reputation:
Rep Power: 5
Solved Threads: 0
•
•
•
•
Originally Posted by rishiraj_bayerd
Hi mahen,
We can calculate decimal number very easily [eg.c=a+b.]
we can operate any arithmatical operation on decimal numbers
in C.
Using atoi(a macro) we can convert a string to integer.
Syntax:
int atoi(const char *s);
Prototype:
stdlib.h
thanking you...
Rishi.
Hi rishi & everyone else,
I simply want the program to accept decimal numbers directly from STDIN & perform arithmetic operations on it.
ps. Really appreciate your help :mrgreen:
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- [Member of the Month - Mar '04] Recruit new members! (Geeks' Lounge)
- pointer to member? (C++)
- Is ifs is a member function of ifstream class (C++)
- [Member of the Month - June '04] HJT Log Help (Windows Users Lounge)
- [Member of the Month - Feb '04] Popular Thread challenge! (Geeks' Lounge)
Other Threads in the C Forum
- Previous Thread: how to let the user select and change the coefficients of a cubic
- Next Thread: problem with convert jumbled text file to unjumbled text file


Linear Mode