3 Replies - 293 Views - Last Post: 30 January 2013 - 07:06 PM Rate Topic: -----

#1 greatroda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 29-January 13

how to store a character/string from the user in an array?

Posted 29 January 2013 - 02:22 AM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: how to store a character/string from the user in an array?

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

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
Was This Post Helpful? 0
  • +
  • -

#3 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

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)
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1086
  • View blog
  • Posts: 4,563
  • Joined: 09-June 09

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.

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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1