Filling an array of characters....

I have problems declaring and filling an array of characters.

By the way: I want to fill that array with ASCII Codes (i.e. a-z and A-Z) and therefore thought of something like:

for (i;i=<52;i++) {
//fill array[i]=asc(i) <-- I know asc() is from basic. what is the //counterpart in C
}

Thanks


StapmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

danny_pavCommented:
cycle through them using char

char val = 'a';

++val;

now val holds 'b'

cycle all the way to 'z'

same with
val = 'A' + 4;
val now holds 'E';

etc.

this should get you going in the right direction.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
StapmanAuthor Commented:
Ok. That should do the thing concerning the information I want to fill into the array. But how do I do that (declaration of array of characters and filling that array with the information).

Thanks
0
KangaRooCommented:
In C/C++ the integer value of a char IS the ASCII value. Where in basic you would write:
  dim i as integer
  dim c as character ' Made that up?
  i = asc("a")
  c = chr(i)
in C this becomes,
  int i;
  char c;
  i = 'a';
  c = i; // c = (char)(i)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

jasonclarkeCommented:
so to fill a..zA..Z your code becomes...

char array[52];
for (int i=0;i<52;i++) {
    array[i] = (i<26)?'a'+i:'A'+(i-26);
}
0
danny_pavCommented:
declare you array:

type name[const_expression_count];

so it becomes

char a[52];

do your for loop:
for (initializer; loop_continue_check; incrementer)
statement;

so it becomes
for (int i = 0, char fill = 'a'; fill <= 'Z'; ++i, ++fill)
{
if (fill == ('z' + 1))
  fill = 'A';
a[i] = fill;
}
0
StapmanAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.