Name Problem: First, Middle, Last

This is a discussion on Name Problem: First, Middle, Last within the C Programming forums, part of the General Programming Boards category; Hey everybody, now i am working on this program that will ask you your name and then says Welcome (name), ...

  1. #1
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17

    Name Problem: First, Middle, Last

    Hey everybody, now i am working on this program that will ask you your name and then says Welcome (name), but i also want it to be able to say your full name like Welcome (first, middle, last), but every time i put 1 or 2 words in like (first, last) in it does nothing.

    See for you self, its hard to explain
    Code:
    #include<stdio.h>
    
    int main(Void)
    {
        char First[25];
        char Middle[25];
        char Last[25];
        
        printf("Please Enter Your Name: ");
        scanf("%s%s%s", First, Middle, Last);
        
        if(Middle == || Last == )
        {
        printf("Welcome %s", First);           
                       }
        
        getch();
        }

  2. #2
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    That doesn't even compile.
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  3. #3
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    Sorry

    Code:
    #include<stdio.h>
    
    int main(Void)
    {
        char First[25];
        char Middle[25];
        char Last[25];
        
        printf("Please Enter Your Name: ");
        scanf("%s%s%s", First, Middle, Last);
        
        if(Middle == 0)
        {
        printf("Welcome %s", First);           
                       }
        
        getch();
        }

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    don't use stuff like getch()
    it doesn't make your code portable..you need to use conio.h...
    better to use getchar() at least

    %s returns when it sees a space or newline..so i think a trick is to do
    "%s %s %s"..but I suggest you use fgets or separate the scanfs instead of a quick shortcut
    You ended that sentence with a preposition...Bastard!

  5. #5
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    I have done this to it but it still won't work

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int main(Void)
    {
        char First[25];
        char Middle[25];
        char Last[25];
        
        printf("Please Enter Your Name: ");
        scanf("%s", First);
        scanf("%s", Middle);
        scanf("%s", Last);
        
        if(Middle == 0)
        {
        printf("Welcome %s %s", First, Last);           
                       }
        
        else if(Middle, Last == 0)
        {
        printf("Welcome %s", First);           
                       }
        
        getch();
        }

  6. #6
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by Sedition X View Post
    I have done this to it but it still won't work

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int main(Void)
    {
        char First[25];
        char Middle[25];
        char Last[25];
        
        printf("Please Enter Your Name: ");
        scanf("%s", First);
        scanf("%s", Middle);
        scanf("%s", Last);
        
        if(Middle == 0)
        {
        printf("Welcome %s %s", First, Last);           
                       }
        
        else if(Middle, Last == 0)
        {
        printf("Welcome %s", First);           
                       }
        
        getch();
        }

    else if(Middle, Last==0)

    incorrect... else if (Middle ==0 && Last==0)

    ...
    why're you comparing with 0?
    You ended that sentence with a preposition...Bastard!

  7. #7
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    I am comparing with 0 because i don't know what else to compare it with, any ideas?

  8. #8
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by Sedition X View Post
    I am comparing with 0 because i don't know what else to compare it with, any ideas?
    i asked because I have no idea why you want the if statement for..
    on what condition do you want to display the first name, or first and last name?
    You ended that sentence with a preposition...Bastard!

  9. #9
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    I want it to be able to display the first, last and middle name if necessary

  10. #10
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    what do you mean by "if necessary"

    i mean the user would have to enter an input i guess...
    but what you're doing..the logic is wrong.
    you're checking if you're attempting to check if your string is empty..and knowing that yet you still try to print something (if Middle is empty, we're assuming that Last and First aren't as well).

    can you be more clear on why you want to display the strings if necessary
    You ended that sentence with a preposition...Bastard!

  11. #11
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    I want to be able to type in the first name, the middle name and the last name but not all at the same time.

  12. #12
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    i thought you wanted to display them?
    btw does it compile for you..
    You ended that sentence with a preposition...Bastard!

  13. #13
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    I want them to come up on screen, and yes it does compile for me

  14. #14
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    odd..i would have thought "Void" would cause an error

    printf("%s %s %s", First, Last, Middle) ;

    no need for if statements
    You ended that sentence with a preposition...Bastard!

  15. #15
    Registered User Sedition X's Avatar
    Join Date
    Jan 2011
    Location
    Tasmania, Australia
    Posts
    17
    Do you have a code??

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  3. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM
  4. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM
  5. Having problem deleting node in middle of stack
    By sballew in forum C Programming
    Replies: 3
    Last Post: 10-29-2001, 10:00 AM

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