scanf to gets

This is a discussion on scanf to gets within the C Programming forums, part of the General Programming Boards category; can someone tell me how i can transfer scanf("%s",input->album); to a gets (); function. thx...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    21

    scanf to gets

    can someone tell me how i can transfer

    scanf("%s",input->album);

    to a gets (); function.

    thx

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    scanf("%[^\n]",input->album);

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    21

    spaces

    i cant use scanf as i want to keep spaces

    however when i try fgets it dont let me enter anything

    i know scanf works which is why i wanted a gets version

    VVV can you help

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    21
    case 1: /*Reading in data*/
    printf("\nEnter the artist: ");
    //fgets((input)->artist);
    fgets( ( *input ).artist, 48, stdin ); ( *input ).artist[strlen( ( *input ).artist ) - 1] = 0;
    printf("%s", (*input).artist);
    //puts((*input).artist );
    fgets( buffer, 20, stdin );

    ok like this it works
    but the string is lost

    like this

    case 1: /*Reading in data*/
    printf("\nEnter the artist: ");
    //fgets((input)->artist);
    fgets( ( *input ).artist, 48, stdin ); ( *input ).artist[strlen( ( *input ).artist ) - 1] = 0;
    printf("%s", (*input).artist);
    //puts((*input).artist );
    //fgets( buffer, 20, stdin ); <----note

    Enter the artist: Enter the album:

    thus stopping me from entering artist

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    21

    just got head back for a sec

    moved buffer and it worked


    thx VVV my program is all down to you as you know

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 07:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 05:34 AM

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