473,324 Members | 2,254 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,324 software developers and data experts.

Function using enumerated values and arrays in C

17
I want this function (which is a part of a larger program) to read a bunch of letters (they will all be different letters) and assign the index of that letter in the array to carry the value TRUE. there are two arrays i want to do this do: set_A and set_B.
actually, i made an enumeration type earlier in the program which defines all lowercase letters as type letters. it was necessary that i use the enum type.
This is not working properly at all. It compiles but doesnt do what i want it to. i think the main problem is in the bold parts.

Expand|Select|Wrap|Line Numbers
  1. void getArray(bool set_A[],bool set_B[])
  2. {
  3.      letters let;
  4.      for (let=a; let<=z; let++)
  5.      {
  6.          set_A[let]=FALSE;
  7.          set_B[let]=FALSE;
  8.      }
  9.      printf("Enter the string of letters for Set A: ");
  10.      while((let=getchar()) != EOF)
  11.      {
  12.          set_A[let]=TRUE;
  13.          }
  14.      printf("\nEnter the string of letters for Set B: ");
  15.      while(( let=getchar()) != EOF)
  16.      {
  17.         set_B[let]=TRUE;
  18.          }
Aug 2 '08 #1
6 1805
Savage
1,764 Expert 1GB
Why does it need to be a enumeration?
Have you defined EOF too?

Does it run infinitely inside the while loop?
If not,what is the output you are getting?

PS:Please be more descriptive when posting questions. Our posting guidelines are of great help there.
Aug 2 '08 #2
ab12
17
No, it doesn't run infinitely. rather, i input the string of letters and then i press ENTER and nothing happens. i thought i would use EOF so when i pressed ENTER i could stop the input. i have to use enumeration types because that is a requirement for this assignment.
what i want is the following: for example if i input 'acde' for set_A, i first want let=a so set_A[a]=TRUE, and then let=c so set_A[c]=TRUE and so on.
Aug 2 '08 #3
ab12
17
Why does it need to be a enumeration?
Have you defined EOF too?

Does it run infinitely inside the while loop?
If not,what is the output you are getting?

PS:Please be more descriptive when posting questions. Our posting guidelines are of great help there.
No, it doesn't run infinitely. rather, i input the string of letters and then i press ENTER and nothing happens. i thought i would use EOF so when i pressed ENTER i could stop the input. i have to use enumeration types because that is a requirement for this assignment.
what i want is the following: for example if i input 'acde' for set_A, i first want let=a so set_A[a]=TRUE, and then let=c so set_A[c]=TRUE and so on.
Aug 2 '08 #4
weaknessforcats
9,208 Expert Mod 8TB
If you inout an A you get 65. I assume then, that you set the bool in element 65 to true? Yes? So your array must be 96 to catch any character you can enter

You see, from inside a function you can't tell the number of elements in an array. Due to decay of array, you don't even know there is an array.

If you have a 26 element array for letters only and you enter A and you want the first element (which is element 0) of the array to be true, then you have to convert the A (a 65) to 0 using an algorithm that will convert B (66) to 1. Then the algorithm shoud also conver a (97) to 0 likewise. If you see what I mean.
Aug 3 '08 #5
ab12
17
If you inout an A you get 65. I assume then, that you set the bool in element 65 to true? Yes? So your array must be 96 to catch any character you can enter

You see, from inside a function you can't tell the number of elements in an array. Due to decay of array, you don't even know there is an array.

If you have a 26 element array for letters only and you enter A and you want the first element (which is element 0) of the array to be true, then you have to convert the A (a 65) to 0 using an algorithm that will convert B (66) to 1. Then the algorithm shoud also conver a (97) to 0 likewise. If you see what I mean.
Thanks i got it to work. to make things simpler, i also changed the EOF to '\n' so i can just hit the RETURN key to end the input
Aug 3 '08 #6
weaknessforcats
9,208 Expert Mod 8TB
Glad to be of help.

Be sure to let us know if you get stuck again.
Aug 3 '08 #7

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

Similar topics

6
by: Colin Steadman | last post by:
I have created a function to kill all session variables that aren't in a safe list. This is the function - Sub PurgeSessionVariables For Each Item In Session.Contents Select Case Trim(Item)...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
6
by: neo88 | last post by:
hi guys Can anyone please tell me what is wrong with this function: inline int strength(void) { int a; // tests to see what strength value the agent just attacked\defended with for (strength;...
3
by: T | last post by:
Hi all. I have a problem I have not been able to find a reference about. I am using VB6 and am only a hobbyist programmer. I have 7 arrays of type MyData. Type MyData has 23 elements. Which...
5
by: Alex Page | last post by:
I've been trying to extend Postgres and create an enumerated type to represent gender, as a precursor to more complex enumerated types. I've created the C functions for input and output with the...
4
by: Isaac | last post by:
Hi mates I want to know a simple program of return array from function ? Do I need to use pointer to return the address of the first element in an array. Isaac
3
by: Claire | last post by:
I have a large record with many enumerated fields. The record is stored in a file and the fields have to be extracted. I validate the data as it's read, but there's so many tests similar to the...
7
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
17
by: binjobster | last post by:
Hello everyone, I'm updating some documents that describes so many C/C++ functions/method(about 2500). But I'm not familiar with these codes. So I want to find such a utility can generate...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.