Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to enter a line of data in C?

    Hi

    I have the code
    Code:
    	printf("Enter the characters:\n");
    	char enc_numbers[10]; //Read in characters
    	gets(enc_numbers);
    Which I am using to read in a line of characters between 1 and 10 (inclusive) characters long. However, if I put this under a previous line using scanf it doesn't work (I'm using scanf to get a single inputted number, which always works).

    I heard that using gets is bad - is this true and how should I read in a line of characters where I don't know how many are going to be entered?

    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •