Thread: strings and numbers

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    strings and numbers

    I have to questions and you might of guessed from the title there about strings and numbers.

    1.) Is there a way so a use can enter a sentance into my program instead of single words. (well want they will be entering is there address because its an address book)?

    2.)Also when I try to save a number with 11 places (a phone number eg. 01298452879) the compilers says its too big how would i be able to save this number into a variable.

    Thanks

  2. #2
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Use fgets and store it into a string. No need to store it as an integer. An int is a 32-bit value and your 11-digit number may exceed the maximum value of an int.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  3. #3
    Registered User
    Join Date
    Aug 2002
    Posts
    109

    i don't understand

    Sorry but I don't think I understand that is it possible that you could explain it like you were talking to a 5 year old.

    Thank you

  4. #4
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    Perhaps an example would help you see it:

    Code:
    #include <stdio.h>
    
    int main()
    {
       char input[20];
       printf("Enter some words: ");
       fgets(input, 20, stdin);
       printf("\nYou have entered: %s\n", input);
       return 0;
    }
    1) You can store multiple words using fgets. It'll stop when you press return.

    2) Don't store a phone number as a number. Store it as a string. Use the same fgets routine above to handle this.

    BTW, read up on fgets and you'll understand better what the function is doing.

    Hope that helps.
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2007, 01:38 PM
  2. strings and numbers
    By jrahhali in forum C++ Programming
    Replies: 5
    Last Post: 09-23-2003, 12:24 PM
  3. convert numbers to strings
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 07-08-2002, 03:43 PM
  4. Replies: 13
    Last Post: 01-22-2002, 04:38 AM
  5. File Access with Strings and Numbers
    By Mace in forum C Programming
    Replies: 3
    Last Post: 12-01-2001, 04:07 AM