LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-19-2004, 10:56 PM   #1
D J
LQ Newbie
 
Registered: Nov 2003
Posts: 13

Rep: Reputation: 0
convert from char* to unsigned char*


Hi all

how can i convert char* to unsigned char*??

class UDPMessage{
public:
UDPMessage(unsigned char* message, unsigned int length);
}

int main(){
char message[1000];
cout << "enter your message";
cin.get(message, 1000);

UDPMessage(message, 1000); //Compiling error here, says "invalid convert from char* to unsigned char*
}

thanks a lot
dejie
 
Old 02-20-2004, 12:00 AM   #2
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
You can use reinterpret_cast, but it's a horrible idea, and I really hesitate to suggest it--but there I did.

There must be a better way:

Code:
#include <iostream>
using namespace std;

class UDPMessage {
	public:
		UDPMessage(unsigned char* message, unsigned int length) {
			for (size_t index(0); index <= length; ++index) {
				cout << message[index];
			}
		}
};

 
int main() {
	char message[1000];
	cout << "enter your message";
	cin.get(message, 1000);
 
	UDPMessage(reinterpret_cast<unsigned char*>(message), cin.gcount());

}
Lyle
 
Old 02-20-2004, 04:09 AM   #3
D J
LQ Newbie
 
Registered: Nov 2003
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks Lyle, alothough i don't kow what you mean the "horrible thing" is, it works fine so far
 
  


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 unsigned char * to unsigned long int linux_lover2005 Programming 3 04-26-2005 11:38 PM
unsigned char in C language exvor Programming 16 03-21-2005 10:24 AM
unsigned char to wchar_t JurajPsycho Programming 6 03-19-2005 04:00 PM
Hex to unsigned char? george_mercury Programming 2 11-27-2004 01:27 PM
C Problem---convert char to char* totti10 Programming 11 11-06-2004 11:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:21 AM.

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