Storing values in strings

This is a discussion on Storing values in strings within the C Programming forums, part of the General Programming Boards category; I was wondering if there was a way to have a string array to store both numbers and letters. For ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Storing values in strings

    I was wondering if there was a way to have a string array to store both numbers and letters. For example, Im writing a digital signal generator program, the user is to input values 0-9,#,*,A-D. My teacher has never went over strings until today, in which he gave a 5 minute overview of it. So Im completely confused.
    I need to store these values in an array so i can use a switch statement to pick different frequencies. For example if the 0th value in the array is A the frequency would be 697 HZ. The only problem is that I don't know how to use strings to read a value in the array everytime I try it freezes on me.

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,049
    Quote Originally Posted by scotty4598 View Post
    I was wondering if there was a way to have a string array to store both numbers and letters. For example, Im writing a digital signal generator program, the user is to input values 0-9,#,*,A-D. My teacher has never went over strings until today, in which he gave a 5 minute overview of it. So Im completely confused.
    I need to store these values in an array so i can use a switch statement to pick different frequencies. For example if the 0th value in the array is A the frequency would be 697 HZ. The only problem is that I don't know how to use strings to read a value in the array everytime I try it freezes on me.
    Check out this short well-written tutorial on strings.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Sorry itCbitC, didn't read your link.

    Scotty eveything in C is a digit.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by strickyc View Post
    Scotty eveything in C is a digit.
    No. I don't know what you're trying to say there, but it's wrong.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by quzah View Post
    No. I don't know what you're trying to say there, but it's wrong.

    Quzah.
    everything is a digit. well, I guess it is kinda wrong. 0 or 1 in sequence. true or false.

    0110 0001 is an 'a' on the ascii therefor a number.

    if you do printf("%d", 'A'); you get the number for A
    or do a printf("%c", 65); you will get A. C doesnt care. It will look it up for you basicly but its still all just digits to C.
    Even the * (42)and an ][93]have digit representations. Also Numbers such as 0, 1, 2, 3 have the same digit representation.

    for 0 it would be 48 so
    Do a printf("%c", 48);
    and it will print a zero.
    C does the work for you in these cases but its all working with digits.

    When you do a
    char letter = 'a';
    its not storing the letter a it is storing the binary number that it looks up for you.
    Last edited by strickyc; 04-29-2009 at 07:32 PM.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    A 'digit' is each of the basic numbers comprising a number system. In base ten, that would be 1 - 9 and 0. The alphabet isn't "digits". Also, not all character sets use the same representation for each character, so 'a' isn't 65 in every set.

    The term you were looking for isn't digit, that was my point.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by quzah View Post
    Also, not all character sets use the same representation for each character, so 'a' isn't 65 in every set.

    The term you were looking for isn't digit, that was my point.


    Quzah.
    I specificly mentioned the ascii character set. Its upon the OP to search the meaning.

    For his assignment he doesn't need a tutorial on string functions.
    what is probaly easiest is to do a char array holding the values of the characters and use a char to store the user input and compare it against the array. Its really just that simple.
    Last edited by strickyc; 04-29-2009 at 08:10 PM.

  8. #8
    Registered User
    Join Date
    Apr 2009
    Posts
    187
    read the ascii character set you can store nums as a string.

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    41
    Quote Originally Posted by elwad View Post
    read the ascii character set you can store nums as a string.
    No if you read the ascii you'll just see what is stored as what and if you write code using the ascii your not really writing for portability. nvm... OP good luck.

  10. #10
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by scotty4598 View Post
    I was wondering if there was a way to have a string array to store both numbers and letters. For example, Im writing a digital signal generator program, the user is to input values 0-9,#,*,A-D. My teacher has never went over strings until today, in which he gave a 5 minute overview of it. So Im completely confused.
    I need to store these values in an array so i can use a switch statement to pick different frequencies. For example if the 0th value in the array is A the frequency would be 697 HZ. The only problem is that I don't know how to use strings to read a value in the array everytime I try it freezes on me.
    What i think is that u can take a char array input each of the characters(alphabets or digits) and terminate that with a NULL character.this will be the rquired string. Then using a loop u can access all those characters. And within that loop u can use ur required switch statement with a case for digits and alphabets.

    @ stricky C
    i completely agree with u that everything in C is stored as combination of bits (binary digits).
    Last edited by BEN10; 04-29-2009 at 11:17 PM.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Storing strings in a linked list
    By dws90 in forum C Programming
    Replies: 1
    Last Post: 02-21-2009, 07:06 PM
  2. storing strings in arrays
    By smp in forum C Programming
    Replies: 6
    Last Post: 12-16-2008, 09:37 AM
  3. storing strings by enum/s
    By l2u in forum C++ Programming
    Replies: 2
    Last Post: 10-07-2008, 09:03 AM
  4. Storing input values while iterating
    By russel1013 in forum C Programming
    Replies: 11
    Last Post: 07-29-2008, 09:32 AM
  5. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 07:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21