Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-25-2008, 05:30 AM   #1
LQ Newbie
Registered: Jun 2008
Posts: 1

Rep: Reputation: 0
Post How to convert char value into integer value in c programming

solution needed
Old 06-25-2008, 06:46 AM   #2
Senior Member
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062Reputation: 1062
Individual characters are integers
#include <stdio.h>

char    c = 'A';

main    ()
        printf ("%d\n", c);
Strings are not and you need to use a function to convert "12345" to 12345:
#include <stdio.h>
#include <stdlib.h>

char    *string = "12345";

main    ()
        printf ("%d\n", atoi (string));

Last edited by tronayne; 06-25-2008 at 06:48 AM.
Old 06-25-2008, 07:09 AM   #3
Senior Member
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Will this help you;
#include <string.h>
#include <stdio.h>
int main()
char szTemp[10];
int nNumber = 0;
strcpy(szTemp, "10"); 
// Convert the string to number.
nNumber = atoi(szTemp);
printf("The converted number is : %d \n",nNumber);
return 0;
Also I've found this site while searching a little,it has some nice things.Anyway you could search yourself a little,because there are so many guides,tutorials and books about C on the net that will help you understand C much better and we have Programming forum here,so you could've started your thread there and searched it a little too.

Last edited by alan_ri; 06-25-2008 at 07:15 AM. Reason: I didn't see tronayne's post


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting char to unsigned integer in c mohtasham1983 Programming 2 02-27-2007 02:58 PM
Convert 64 bit integer to char array in C++ syseeker Programming 2 06-27-2006 03:33 AM
C++ converting from char to integer MicahCarrick Programming 4 12-19-2005 02:16 PM
Convert Integer to Char gjagadish Programming 5 10-14-2005 10:09 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:00 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration