Solved

converting string to int

Posted on 2004-04-28
6
182 Views
Last Modified: 2010-04-15
hello.  I have a string that represents the coefficients of an equation.  i need to parse this and eventually convert each coefficient to it's integer or float equivalent.
for example,
"8 6 -6/7 +22/16 "
means 8 = 6(x1) -6/7(x2) +22/16(x3)

i'm thinking of using strtok( ) to get each of the coefficients separately, but then what do i do next? i tried to cast the string to an integer, but that doesn't work.   please help.  thank you.  i'm sorry i can't offer that many points for this, it's b/c i'm a new user.
0
Comment
Question by:naz4viper
  • 3
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 10943416
use atoi
0
 
LVL 30

Accepted Solution

by:
Axter earned 25 total points
ID: 10943422
Example:
char data[] = "123";
int num_data = atoi(data);
0
 
LVL 30

Expert Comment

by:Axter
ID: 10943431
If you need to convert it to float, then you can use atof
0
 
LVL 9

Assisted Solution

by:ankuratvb
ankuratvb earned 25 total points
ID: 10945447
Adding to what Axter has already pointed out,
atoi() & atof() require stdlib.h

And they take care of your signs as well,
if you have char ptr[]="-123";
int p=atoi(ptr);

then,p=-123;

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Convert image to byte array 8 189
Which checksum is this? 7 139
List out all word 7 259
Global Keyboard Hooks Blocked 4 70
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now