LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-04-2010, 04:08 AM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
i need to convert a char * to unsigned char


is it possible to convert a variable from char * to unsigned char ?

please help me
 
Old 03-04-2010, 04:15 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Do you mean from char * to unsigned char *?

A char and a pointer are totally different.
 
Old 03-04-2010, 04:26 AM   #3
karthi_27
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
If you mean char * to unsigned char , you can do that but you can only change the first character in the char *.

Code:
#include<stdio.h>
main()
{
        char *c="asdd";
        printf("%d\n",(unsigned char)*c);
}
Here you will get the result as 97.Because the ascii value of a is 97.
 
Old 03-04-2010, 11:54 AM   #4
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Code:
char *p;
unsigned char x;
x=(unsigned char)*p;
OR do you want:
Code:
char *p;
unsigned char *x;
x = (unsigned char *)p;
 
Old 03-04-2010, 12:07 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi, anurupr -
Quote:
Q: Is it possible to convert a variable from char * to unsigned char ?

A: Yes
Quote:
A char and a pointer are totally different.

Absolutely "Yes".
The fact is, in C/C++ you can convert just about anything to just about anything else. It's all "bits", and C gives you lots of power and flexibility.

The real question (the one everybody's asking you) is:
Quote:
Q: What exactly are you trying to do?
Not *how*, but *what*? What, conceptually, is your GOAL?

We need to know the "context" of your question.

Thank you in advance .. PSM

Last edited by paulsm4; 03-04-2010 at 02:53 PM.
 
Old 03-04-2010, 02:55 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.
 
  


Reply



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
Convert ip address from char* to unsigned int* Kunsheng Programming 6 04-29-2009 02:12 PM
difference between char and unsigned char..?? sumitshining Programming 8 11-17-2008 08:08 PM
conversion from ‘const char*’ to ‘unsigned char*’ rubadub Programming 2 02-08-2008 05:45 PM
convert unsigned char * to unsigned long int linux_lover2005 Programming 3 04-26-2005 11:38 PM
convert from char* to unsigned char* D J Linux - Software 2 02-20-2004 04:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 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
Open Source Consulting | Domain Registration