A question about loops and scanf

This is a discussion on A question about loops and scanf within the C Programming forums, part of the General Programming Boards category; If I wanted to use a loop with scanf(), what should I use ? Thank You...

  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,825
    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,825
    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-19-2008, 12:26 AM
  4. Help Me Find My Error Please (loops)
    By tru.cutru in forum C Programming
    Replies: 6
    Last Post: 06-30-2008, 08: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

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