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
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
char my_array [] = "Hello everyone";
I think that should do it.
http://uk.geocities.com/ca_chorltonkids
To be more preciseCode:#include <stdio.h> int main(void) { char my_array [30]; printf("Please enter your name:"); scanf("%s",&my_array); printf("\nHello %s",my_array); }
http://uk.geocities.com/ca_chorltonkids
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.
You each have an "error".
First poster) You didn't return 0;
Second poster) You forgot to scope cout and endl to namespace std;
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.
The highlighted line should readOriginally posted by crag2804
To be more preciseCode:#include <stdio.h> int main(void) { char my_array [30]; printf("Please enter your name:"); scanf("%s",&my_array); printf("\nHello %s",my_array); }
>scanf("%s",my_array);
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
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.
alrigh thanks, it works but can you explain the code so i can understand it for future use?
Does this make a little more clearCode:#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; }
yea i understand it now!! thanks for the help!