i declared it just the same as an integer nor double but it errors on converting i think.
my problem is on how to store character/string from the users input in array.
3 Replies - 117 Views - Last Post: 30 January 2013 - 07:06 PM
#1
how to store a character/string from the user in an array?
Posted 29 January 2013 - 02:22 AM
Replies To: how to store a character/string from the user in an array?
#2
Re: how to store a character/string from the user in an array?
Posted 29 January 2013 - 02:34 AM
Can you please post the code that you have tried for this...it will enable us to understand your problem better.
regards,
Raghav
regards,
Raghav
#3
Re: how to store a character/string from the user in an array?
Posted 29 January 2013 - 02:41 AM
The guys who invented computer languages are rather brilliant, so take a cue from them - and if you want to store a char or a string, use a char data type (either a single one for a single char, or a multiple char array for a string.
Sounds like you would benefit by running through a tutorial for C or C++, as well. There are many of them listed by Google search.
If you're still confused, post up what you're trying to make work, and we'll see what the problem is.
(always surround your code with code tags - just highlight your code, and click on the [code] icon in the editor)
Sounds like you would benefit by running through a tutorial for C or C++, as well. There are many of them listed by Google search.
If you're still confused, post up what you're trying to make work, and we'll see what the problem is.
(always surround your code with code tags - just highlight your code, and click on the [code] icon in the editor)
#4
Re: how to store a character/string from the user in an array?
Posted 30 January 2013 - 07:06 PM
[quote
my problem is on how to store character/string from the users input in array.
[/quote]
C++ you can use the std::string object and can read directly from the input stream, no need for boundary checking.
In C, you use scanf (ignores white space) with a format specifier to check boundries, or you can use fgets.
Note that either of the above functions will added a null terminator.
my problem is on how to store character/string from the users input in array.
[/quote]
C++ you can use the std::string object and can read directly from the input stream, no need for boundary checking.
std::string input; std::cin>>input;
In C, you use scanf (ignores white space) with a format specifier to check boundries, or you can use fgets.
char buffer[50];
scanf("%50s", buffer);
//or
fgets(buffer, 50, stdin);
Note that either of the above functions will added a null terminator.
This post has been edited by jjl: 30 January 2013 - 07:06 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|