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????.

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.....

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.

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

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'.

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 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:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.