how do i assign the string input of a user to a char? cin>> only gets the part before the first space; for instance, say a user inputs "This is a test." i'd like ot assign that to a char
This is a discussion on user string input within the C Programming forums, part of the General Programming Boards category; how do i assign the string input of a user to a char? cin>> only gets the part before the ...
how do i assign the string input of a user to a char? cin>> only gets the part before the first space; for instance, say a user inputs "This is a test." i'd like ot assign that to a char
> how do i assign the string input of a user to a char? cin>>
Well, first of all, this is the C board, so I wouldn't use cin.
> how do i assign the string input of a user to a char? cin>>
Secondly, you can't assign a string from the user to a char. You'd have to do it to a char * or an array of characters. I'm not sure if you are trying to do this in C or C++. But, I'll show you how to do it in C. If you want to know how to do it in C++, go to that board:
I don't know about C++, but that's how you get a string from the user in C.Code:int main() { char name[50]; printf("Enter your name: "); fgets(name, sizeof(name), stdin); printf("Your name is %s", name); return (0); }