473,396 Members | 1,852 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

datatype to store both char n int in an array

hi, wat datatype to use if i want to store both integers & char in an array? can i use String...and how to use String?
Mar 25 '08 #1
5 7614
gpraghuram
1,275 Expert 1GB
hi, wat datatype to use if i want to store both integers & char in an array? can i use String...and how to use String?
You should go for a structure which contains the members char and int and use the structure array to store the values

raghuram
Mar 25 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
You won't be able to use String with integers or array members that are struct variables.
Mar 25 '08 #3
I think you can use int data type to store both integer and character data type...
Eg:int data = 'A';
Mar 26 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
A char and an int are both integers. The char is 8 bytes and the int is at least 16 but may be more.

There are no character variables.

That means an int with 65 can be displayed as A just as well as a char with 65. It's just that functions with char arguments assume you want to see the A whereas functions with int arguments assume you want to see 65.

The syntax 'A' is an integer syntax. It tells the compiler to look up the value corresponding to A in the ASCII table and to use that value. In this case, 65.
Mar 26 '08 #5
Thanks... It worked for me ... i created a structure and its array as u told...
struct maze{int x;char y;};
void main ()
{maze a[10][10];

//to store in int part
cin>>a[0][0].x;
//to store in char part
cin>>a[0][0].y;

//to access int part
cout<<a[0][0].x;
//to access char part
cout<<a[0][0].y;


}
Feb 14 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Steve | last post by:
Hello (and a happy new year) I'm quite new to C++ and have to programm something for school and can't get my head around a couple of things, but at the moment this one is the most important for...
4
by: c_bowen | last post by:
I am using Visual Studio .NET 2003 with SQL Server 2000. I am trying to insert the date and time into a SQL database by using hour(now). I am having a hard time trying to figure out which datatype...
12
by: arkobose | last post by:
my earlier post titled: "How to input strings of any lengths into arrays of type: char *array ?" seems to have created a confusion. therefore i paraphrase my problem below. consider the...
2
by: aengus | last post by:
Hi, I am looking to find out how to deal with the BYTE datatype in VC, as used below: This struct is part of the API for a Garmin GPS unit: typedef struct { unsigned char mPacketType; ...
8
by: Vinod | last post by:
Hi, I have a stored procedure which expects a varbinary datatype. How can i pass a varbinary datatype from asp.net directly to the stored procedure. I tried using the Convert function in Sql...
1
by: Bryan | last post by:
I have a class called "Prop". I want that class to have a property called "DataType" where the user can select and store a datatype. How can I store a DataType value in a class property. how...
36
by: Rahul K | last post by:
Hello all Suppose I am given a datatype say X in C. How can i find its size without declaring a variable or pointer variable of that type, and of course without using sizeof operator.
4
by: Orchid | last post by:
How can I change a Date datatype to a Number datatype? For example, I want a date 10/31/2006 to show 1031 as Number datatype. But I don't want it becomes 39021. What formula should I use? ...
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.