In this program, i am trying concatenate different inputs that have been defined by the user. The problem comes in when i am trying to make a phrase such as "This is a test" where the output will only be "Thisisatest". I am not too sure how to go about including white spaces, i have tried to use noskipws and strcat with no success. Thanks in advance.
void printArray (char arg [], int i)
{
int j = 0;
while (j < i)
{
cout << arg [j];
j = j + 1;
}
cout << endl;
}
void ptrPrintArray ( char arg [], int j)
{
int i = 0;
char * ptr;
ptr = arg;
while (i < j)
{
cout << *ptr;
ptr ++;
i = i + 1;
}
}
int main ()
{
char chararray [80];
char inputchar;
int i = 0;
cout << "Input char: ";
cin >> inputchar;
while (inputchar != '$')
{
chararray [i] = inputchar;
i = i + 1;
cin >> inputchar;
}
Here is the solution.
1) You have to use string instead of char.
2) Then you have to use getline (cin, inputchar);
I have not changed the variable names, just changed the type.
I hope you will like it.
ahhhh yes that would make sense, i originally started with strings but then changed to chars thinking it would consider white spaces as a character. Thanks a bunch guys =D
ahhhh yes that would make sense, i originally started with strings but then changed to chars thinking it would consider white spaces as a character. Thanks a bunch guys =D
Something more, your concept about char, if you use cin >> with char, then i tell you that cin just takes the input before the first white space, if you give input as "this is" then it has just took "this" as input
while in case vlad told above cin.get takes enter as input too with given char.
Have fun!