LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 06-25-2008, 06:30 AM   #1
kpratheep
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, 07:46 AM   #2
tronayne
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: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060Reputation: 1060
Individual characters are integers
Code:
#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:
Code:
#include <stdio.h>
#include <stdlib.h>

char    *string = "12345";

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

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

Rep: Reputation: 127Reputation: 127
Welcome!
Will this help you;
Code:
 
#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 08:15 AM. Reason: I didn't see tronayne's post
 
  


Reply


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 03:58 PM
Convert 64 bit integer to char array in C++ syseeker Programming 2 06-27-2006 04:33 AM
C++ converting from char to integer MicahCarrick Programming 4 12-19-2005 03:16 PM
Convert Integer to Char gjagadish Programming 5 10-14-2005 11:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:38 PM.

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