473,757 Members | 3,768 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert to Static Char

Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.

Thx

Jul 23 '05 #1
5 6193
Ia******@hotmai l.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.


What exactly do you mean by "Static Char"?

Jul 23 '05 #2
Ia******@hotmai l.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.

Thx


Try this:
static char c;

int main(void)
{
c = 'A'; // Converts 'A' into a static char.
c = '1'; // Converts a literal numeric into a char.
return 0;
}

If this doesn't satisfy you, please be more descriptive
as to what you are seeking.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.l earn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #3

"Thomas Matthews" <Th************ *************@s bcglobal.net> wrote in
message news:42******** ****@sbcglobal. net...
Ia******@hotmai l.com wrote:
Hi

I was wondering if anyone knew how to convert a string or an integer
into a Static Char.


Try this:
static char c;

int main(void)
{
c = 'A'; // Converts 'A' into a static char.
c = '1'; // Converts a literal numeric into a char.
return 0;
}

If this doesn't satisfy you, please be more descriptive
as to what you are seeking.

--
Thomas Matthews


Well, considering he asked about converting a string or an integer, and
since 'A' is not a string and '1' is not an integer, I suspect it won't
satisfy.

Like you, however, I await clarification as to exactly what the heck he
*does* want! :-)

To the OP:

When you say you want to "convert ... to a static char", that doesn't really
make sense. Do you mean you want to know how to put the contents of a
string (i.e., std::string) into an array of char (a C-style string), and how
to convert an integer into an C-style string as well? Or...???

A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's outside
the range of 0..9) or a string (if the string is longer than 1 character).

With the keyword "static" in front of it, it means different things,
depending upon where it's used. A static member variable is different from
a non-member variable declared as static. (I hate that those different
concepts use the same keyword, but what're you gonna do, eh? :-))

Research the keyword "static". Also research "array of char", or C-style
strings. And if by "string" you meant the class std::string, look that up,
too.

-Howard

Jul 23 '05 #4
Howard wrote:
A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's outside
the range of 0..9)

I am sure you did not mean what it sounds that you said, but we have to
be technically correct. :-)

A char can hold integer values from numeric_limits< char>::min() to
numeric_limits< char>::max() the latest being always at least 127.
The following code displays these ranges in a system:
#include <iostream>
#include <limits>

int main()
{
using namespace std;

cout<<static_ca st<int>( numeric_limits< char>::min() )<<"\n"
<<static_cast<i nt>( numeric_limits< char>::max() )<<"\n";
}
In my system it outputs:

C:\c>temp
-128
127

C:\c>

--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #5

"Ioannis Vranos" <iv*@remove.thi s.grad.com> wrote in message
news:1109640191 .100742@athnrd0 2...
Howard wrote:
A char (watch your capitalization, it's important in C++) is a single
character, and is not going to be able to hold an integer (if it's
outside the range of 0..9)

I am sure you did not mean what it sounds that you said, but we have to be
technically correct. :-)


Right, sorry. What I meant was that if you are using an array of char to
display an integer that has been "converted" to a string, such as with itoa,
sprintf, or a stringstream, then a single char in that array will only hold
one decimal digit of that integer. So the number 127 would need an array of
at least three chars, i.e., ['1','2','7'] (plus one more for the
null-terminator if used as a C-style string). And since the OP asked about
converting an integer to a {static} char, I wanted to point out that he
probably meant an _array_ of char, not just a single char. Assuming, of
course, I understood what he meant by "convert"! :-)

Thanks,
Howard


Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
16046
by: Abhishek Jha | last post by:
How can we write a shortest program in c to convert given number to words format. example input 5012 Output: five thousand tewlve.
7
7120
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done without strtol or s/printf function. Thanks, whatluo.
7
6758
by: Jim | last post by:
I have to access a third party api to work with their hardware. Everything was going great UNTIL I ran into the problem of C# char being 16 bits and the C char being 8 bits. I cannot seem to cast the string properly to use it in the unmanaged code. I have tried to use the MarshalAs function in my DllImport statement but that didn't work. What i need is to take a string of numbers and convert it
4
4719
by: Ping | last post by:
Hi, All, We can use BitConverter.ToString(byte) to a string, but how to get the byte from a string like "AD-A6-0D-1F"?
25
7301
by: Charles Law | last post by:
I thought this was going to be straight forward, given the wealth of conversion functions in .NET, but it is proving more convoluted than imagined. Given the following <code> Dim ba(1) As Byte Dim b As Byte
30
17380
by: ceeques | last post by:
Hi I am a novice in C. Could you guys help me solve this problem - I need to convert integer(and /short) to string without using sprintf (I dont have standard libray stdio.h). for instance:- int i =2; char ch 'A'
3
13823
by: GM | last post by:
Dear all, Could you all give me some guide on how to convert my big5 string to unicode using python? I already knew that I might use cjkcodecs or python 2.4 but I still don't have idea on what exactly I should do. Please give me some sample code if you could. Thanks a lot Regards, Gary
40
1797
by: Tameem | last post by:
hi my name is tameem. i am a new c programmer. in a c program i want to give input ""tameem"" and the output will be ""xdphhp"" in a short: the character ""a"" will be replaced by ""d"" i can convert only a character.so how can i convert a word or a sentence my character convert program is given below: #include<stdio.h>
4
4660
by: Peter | last post by:
Does anyone know how to convert the following VB6 code to C# code? Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, Source As Any, ByVal bytes As Long) Dim sngArray(0) As Single strString = Chr$(107) & Chr$(62) & Chr(139) & Chr$(65) CopyMemory sngArray(0), ByVal strString, Len(strString) After running the code sngArray(0) = 17.40548
0
9487
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9735
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8736
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.