Thread: A question about loops and scanf

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    A question about loops and scanf

    If I wanted to use a loop with scanf(), what should I use ?

    Thank You

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    That depends on what you wanted to do... AFAIK, your choice of loop should be dictated by how you want it to execute, not the fact that you're using scanf

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    What I wanted to was to type in a name

    James Bellweather





    Result would be

    Bellweather, J.

    I need to do this with 10 names. I have 75 of the code done.
    The code is

    #include <stdio.h>

    int main()
    {

    int c;
    char first[8];
    char last [9];
    char middle[11];

    {
    printf("\nINPUT\n");

    /* Here is where the loop will be going */
    {
    scanf(" %s,", first);
    scanf(" %s,", last);
    scanf("//");
    }

    printf("\nOUTPUT:\n");
    printf("%s, %s\n", last, first);
    }


    return 0;

    }

    Please Help.
    Thank You

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Well, since it's running a predetermined number of times, I'd say to use a for loop:

    for (i = 0;i<10;i++)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf is being skipped
    By yougene in forum C Programming
    Replies: 6
    Last Post: 12-24-2008, 06:05 AM
  2. Problems with functions and for loops
    By slava in forum C Programming
    Replies: 1
    Last Post: 11-08-2008, 01:30 PM
  3. checking if int when using scanf. Help!
    By xtrmi in forum C Programming
    Replies: 4
    Last Post: 09-18-2008, 11:26 PM
  4. Help Me Find My Error Please (loops)
    By tru.cutru in forum C Programming
    Replies: 6
    Last Post: 06-30-2008, 07:27 PM
  5. simple input and string manipulation question
    By Stig in forum C Programming
    Replies: 1
    Last Post: 12-15-2001, 01:33 PM