How to convert string into int in C programming

  • clapika
  • Born
  • Born
  • clapika
  • Posts: 1

Post 3+ Months Ago

Hello,
i want to convert string value into int in C programming

Example:
Char *word="22";
int no;

how to insert this word into no ? please help me...
Thx....
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9090
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I would use the atoi function:

Code: [ Select ]
int atoi ( const char * str );


Parses the C string str interpreting its content as an integral number, which is returned as an int value.

There are also some related functions you could use:

atol (Convert string to long integer)
atof (Convert string to double)
strtol (Convert string to long integer)

Make sure you include the stdlib.h library:

Code: [ Select ]
#include <stdlib.h>

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 120 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.