Thread: String input problem, gets

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378

    String input problem, gets

    hey, i'm having a problem with my input function. i've had the problem before.. but i dont remember what the solution is. for some reason, when my program hits the gets input it goes straight through it.. so how do i make this work? here's my code for this function:
    Code:
    void encrypt_text(int random_number, char *key)
    {
         char text[255];
         char *pt;
         int stringlength, counter;
         
         if (random_number == 70) { --random_number; }
         
         /* user input of string to be encrypted */
         printf("\n\nEnter your text: ");
         if ((pt = gets(text)) == NULL)
         {
              printf("\nError on input.\n");
         }
         
         /* find length of string entered */
         stringlength = strlen(text);
    
         /* find string length for loop */
         counter = 0;
         do {
               text[counter] = text[counter]^key[random_number];
               printf("%c", text[counter]);
               ++counter;
         } while (counter <= stringlength);
    }
    Last edited by willc0de4food; 03-04-2005 at 06:29 AM.
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  4. string problem
    By INeedSleep in forum C++ Programming
    Replies: 24
    Last Post: 11-08-2007, 11:52 PM
  5. ........ed off at functions
    By Klinerr1 in forum C++ Programming
    Replies: 8
    Last Post: 07-29-2002, 09:37 PM