?
Solved

converting string to int

Posted on 2004-04-28
6
Medium Priority
?
217 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 10943416
use atoi
0
 
LVL 30

Accepted Solution

by:
Axter earned 100 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 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

770 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