newbie help

This is a discussion on newbie help within the C++ Programming forums, part of the General Programming Boards category; im using microsoft VC++ 6, i was just wondering (i know this is a stupid question but) how do i ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    10

    newbie help

    im using microsoft VC++ 6, i was just wondering (i know this is a stupid question but) how do i set a string? like i want to make a lil program that you have to enter your anem and it says like " hello name" thanks fgor any help

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    137
    char my_array [] = "Hello everyone";

    I think that should do it.
    http://uk.geocities.com/ca_chorltonkids

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    137
    Code:
    #include <stdio.h>
    int main(void)
    {
       char my_array [30];
       printf("Please enter your name:");
       scanf("%s",&my_array);
       printf("\nHello %s",my_array);
    }
    To be more precise
    http://uk.geocities.com/ca_chorltonkids

  4. #4
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    And if you don't like using printf:

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    char name[10];
    
        cout << "What is your name?\n";
        cin >> name;
        cout << "\nHello " << name;
        
        return 0;
    }
    Last edited by Kirdra; 09-14-2002 at 04:29 PM.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    You each have an "error".
    First poster) You didn't return 0;
    Second poster) You forgot to scope cout and endl to namespace std;

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1
    It is better to start on a dialog box program.
    1. Click File-New-Projects-MFC Appwizard (EXE).
    2. Type "AnyName" on the Project Name Dialog Box.
    3. Click OK.
    4. Select "Dialog Based" then click "Finish" Button.
    5. Click OK.
    6. click "Edit Box" on the controls toolbar.
    (controls toolbar is located on the left side, normally)
    7. click on the form. This will add the edit box on the form
    8. Right click on the edit box then select Properties.
    9. Rename IDC_EDIT1 to IDC_NAME
    10. Right click on the "AnyName" Form then select ClassWizard.
    11. Select "Member variables" tab
    12. Select IDC_NAME then click add variablre.
    13. Change m_ to m_strName.
    14. Click OK.
    15. Click OK.
    16. Double click OK button on the "AnyName" Form.
    17. Click OK.
    18. Type "UpdateData();" after the
    //TODO... line.
    19. Type "MessageBox(m_strName);" next line.
    You are now ready to compile and run the program.

    19. Ctrl F5.
    20. Click Yes.
    wait until the dialog box appear.
    21. Type any word on the edit box.
    22. click ok.
    The name you type appears.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by crag2804
    Code:
    #include <stdio.h>
    int main(void)
    {
       char my_array [30];
       printf("Please enter your name:");
       scanf("%s",&my_array);
       printf("\nHello %s",my_array);
    }
    To be more precise
    The highlighted line should read
    >scanf("%s",my_array);
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User marCplusplus's Avatar
    Join Date
    Nov 2001
    Posts
    68
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    	const int MAX = 20;
    	char name[MAX];
    	cout << "What is your name?\n";
    	cin.getline(name,MAX,'\n');
    	cout << "Hello " << name;
    	return 0;
    }

    Marc
    No matter how much you know, you NEVER know enough.

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    alrigh thanks, it works but can you explain the code so i can understand it for future use?

  10. #10
    Registered User Kirdra's Avatar
    Join Date
    Aug 2002
    Posts
    105
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    char name[10]; //Storing in name total of 9 characters 
                             //and a null which is automatically added
    
        cout << "What is your name?\n"; //Prompting for user input
        cin >> name; // Storing user input
        cout << "\nHello " << name; // Printing User input
        
        return 0; 
    }
    Does this make a little more clear

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    10
    yea i understand it now!! thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 06:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 11:53 AM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM

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