Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert String to int?

Status
Not open for further replies.

threedim

Technical User
Mar 18, 2002
22
MY
I have a situation where i have an output of:
"+CSQ: 39, 0"

I want to be able to store 39 & 0 into an int variable.

Any ideas how I should approach this?
 
Try
int int1,int2;
char *ptr = strtok(&sampleline[5], "/\n");
sscanf(ptr, "%d", &(int1));
ptr = strtok(NULL, "/\n");
sscanf(ptr, "%d", &(int2));
Cheers
DB ;-) Dickie Bird
db@dickiebird.freeserve.co.uk
 
Oops - Sorry - I copied from an existing bit of code and left the separators as I use them - your separators should be ",\n" , not "/\n" ( its a comma between your integers, its a forward slash between my text file input fields)
DB Dickie Bird
db@dickiebird.freeserve.co.uk
 
Thank you, I have used this technique and it has been very helpful :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top