User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Aug 2004
Posts: 76
Reputation: Mahen is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Mahen Mahen is offline Offline
Junior Poster in Training

Help Help a new member

  #1  
Aug 5th, 2004
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????.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2004
Posts: 10
Reputation: Tex_Tootell is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Tex_Tootell Tex_Tootell is offline Offline
Newbie Poster

News Re: Help a new member

  #2  
Aug 5th, 2004
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.....
Reply With Quote  
Join Date: Aug 2004
Posts: 5
Reputation: The Code Poet is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
The Code Poet The Code Poet is offline Offline
Newbie Poster

Re: Help a new member

  #3  
Aug 5th, 2004
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.
Reply With Quote  
Join Date: Aug 2004
Posts: 76
Reputation: Mahen is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Mahen Mahen is offline Offline
Junior Poster in Training

Re: Help a new member

  #4  
Aug 5th, 2004
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
Reply With Quote  
Join Date: Jun 2004
Location: Marin, CA, USA
Posts: 434
Reputation: Chainsaw is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 10
Chainsaw's Avatar
Chainsaw Chainsaw is offline Offline
Unprevaricator

Re: Help a new member

  #5  
Aug 5th, 2004
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'.
Reply With Quote  
Join Date: Jul 2004
Posts: 16
Reputation: rishiraj_bayerd is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
rishiraj_bayerd rishiraj_bayerd is offline Offline
Newbie Poster

Re: Help a new member

  #6  
Aug 6th, 2004
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.
Reply With Quote  
Join Date: Aug 2004
Posts: 76
Reputation: Mahen is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Mahen Mahen is offline Offline
Junior Poster in Training

Solution Re: Help a new member

  #7  
Aug 6th, 2004
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:
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:59 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC