473,378 Members | 1,146 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,378 software developers and data experts.

declaring alpha numeric

how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.

Nov 16 '05 #1
11 10281
shan wrote:

how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.


A structure can hold various types simultaneously.

--
pete
Nov 16 '05 #2

shan wrote:
how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.


Your question is not very clear. Do you mean like this?

int foo = 'a';

foo = 123;

The integer variable foo can be used to hold a letter or a number, is
that
what you are after?

-David

Nov 16 '05 #3
shan wrote:
how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.

int i;
i = 'a';
i = '0';

S.
Nov 16 '05 #4
My question is the variable should hold items like mn995# .

Nov 16 '05 #5

shan wrote:
My question is the variable should hold items like mn995# .


Two things.

1) That looks much like a char array is what is wanted.
Why don't you want to use one? Explain the use to which
you intend to put the variable and why a char array doesn't
meet your needs, and perhaps we can help more? Is this
homework?

2) When replying, please quote stuff so everyone can see the context.
To quote another poster:
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

-David

Nov 16 '05 #6

David Resnick wrote:
shan wrote:
My question is the variable should hold items like mn995# .


Two things.

1) That looks much like a char array is what is wanted.
Why don't you want to use one? Explain the use to which
you intend to put the variable and why a char array doesn't
meet your needs, and perhaps we can help more? Is this
homework?


Maybe he wants something like a structure holding two chars, one int
and one char?

Nov 16 '05 #7
"shan" <sr**********@gmail.com> writes:
how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.


We don't understand the question. You're misusing the word
"alphabets"; what exactly do you mean? There are several kinds of
numbers (integer and floating-point). Do you want a variable that can
hold different things simultaneously? Why should it not be a string
or char array?

Questions of the form "How can I do X without using language feature Y?"
are often homework (in real life, you're free to use whatever language
feature will get the job done). Is this a homework assignment?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 16 '05 #8
"shan" <sr**********@gmail.com> wrote:
# how to declare a variable that should contain both alpahabets and
# numbers.It should not be an string or char array.

C doesn't have anything like a Cobol PICTURE (A).

--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD
Nov 16 '05 #9
shan a écrit :
My question is the variable should hold items like mn995# .

This is nothing but a string.

If you want to give a semantic to the subfields, it's up to you. a
structure can hold it.

--
A+

Emmanuel Delahaye
Nov 16 '05 #10
In article <11**********************@g47g2000cwa.googlegroups .com>,
shan <sr**********@gmail.com> wrote:
how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.


If you want a variable that can contain either numbers or strings,
you could use a union, but you will have to keep track of which it
contains.

If you mean (contrary to what you say) that you want a string that
is restricted to alphanumeric characters, there's no way to do that
in C; you'll have to check it yourself.

-- Richard

Nov 16 '05 #11
shan wrote:
how to declare a variable that should contain both alpahabets and
numbers.It should not be an string or char array.


Here I give you a program in three files. The first is main.c, which
demonstrates the use of the alphanumeric type. The second is
alphanumeric.h, which is a header file that you must include to have
access to the alphanumeric type and the functions that use it. The third
file contains the implementation of the functions.

/* main.c */

#include "alphanumeric.h"

#include <stdio.h>

int main(void)
{
alphanumeric *p = new_alphanumeric("mn955");
if(!p)
{
printf("No, that was not alphanumeric!\n");
return 0;
}
print_alphanumeric(p);
delete_alphanumeric(p);
putchar('\n');
return 0;
}
/* alphanumeric.h */

#ifndef H_ALPHANUMERIC
#define H_ALPHANUMERIC

typedef struct alphanumeric alphanumeric;

alphanumeric *new_alphanumeric(const char *);
void print_alphanumeric(const alphanumeric *);
void delete_alphanumeric(alphanumeric *);

#endif
/* alphanumeric.c */

#include "alphanumeric.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct alphanumeric
{
char *data;
};

static const char *alnum = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";

alphanumeric *new_alphanumeric(const char *s)
{
size_t n = strlen(s);
alphanumeric *new;
if(strspn(s, alnum) != n)
{
return NULL;
}
new = malloc(sizeof *new);
if(!new)
{
return NULL;
}
new->data = malloc(n + 1);
if(!new->data)
{
free(new);
return NULL;
}
memcpy(new->data, s, n + 1);
return new;
}

void print_alphanumeric(const alphanumeric *a)
{
printf("%s", a->data);
}

void delete_alphanumeric(alphanumeric *a)
{
free(a->data);
free(a);
}

/* end of alphanumeric.c */

--
Simon.
Nov 17 '05 #12

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

Similar topics

2
by: entoone | last post by:
I have a field called pword, whenever someone enters anything but numeric, i.e. mixed alpha with numeric, or even just alpha.. the following error appears. Warning: mysql_numrows(): supplied...
7
by: Federico G. Babelis | last post by:
Hi All: I have this line of code, but the syntax check in VB.NET 2003 and also in VB.NET 2005 Beta 2 shows as unknown: Dim local4 As Byte Fixed(local4 = AddressOf dest(offset)) ...
3
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and...
8
by: MLH | last post by:
I have a textbox on a form into which an alpha-numeric string of data is entered. I wish to force the casual user, who would sometimes use upper case, sometimes not and sometimes MIX the case -...
7
by: Peter | last post by:
Any one have a code snippet that would show me how to: 1. Generate a 24 character 2. Random 3. Alpha Numeric data dump 4. into an array IE.
5
by: Bosconian | last post by:
I need a comma delimited regular expression pattern with the followng restrictions: no leading and trailing white space no trailing comma double quoted numeric/alpha pairs each pair on a...
8
by: .Net Sports | last post by:
I am checking for text input on a form validation in javascript that required at least one numeric character along with any number of alpha characters for a given input text box. The below is a var...
1
by: shijith | last post by:
Hi, I am using MS-SQL 2000. I had a varchar column with data formated as Numeric portion + Alpha portion. Id ---- 1 2AA 2DF 2AB
5
lotus18
by: lotus18 | last post by:
Hello World! I have a sample code here written in vb .net that restricts the textbox to accept only alpha, alphanumeric or numeric characters. Public Enum MyOption Alpha = 1 ...
1
by: perl9user | last post by:
Hi, Does anyone know how to get the alpha-numeric numbering scheme in perl ? For example the numberic => 0,1,2,...9,10,11,12,...99,100,... # $x = 0;$x++; lower-alpha =>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.