while loop problem

So I'm trying to create a loop so it would check all the characters in a string array, but I cant quite execute the while loop so well, I'm thinking it keeps on looping. Any suggestions? Thanks for reading.

int i=0;
char string[50];
cout<<"Please enter your name"<<endl;
cin.getline(string,50,'\n');
char ch=string[i];
while(ch!='\0') //I'm not sure if this statement is correct
ch=string[i++];
It works for me, what do you expect it to be doing that it's not?
because I entered a cout statement into the while to check if the loop is running, and it doesn't stop looping. I'm really trying to enqueue the characters into a linked list, but I cant quite get this while loop to work yet.
Well, when I added just a bit to your code, I was able to print out the name confirming that it goes through the entire cstring.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

main ()
{

	int i=0;
	char string[50];
	cout<<"Please enter your name"<<endl;
	cin.getline(string,50,'\n');
	char ch=string[i];
	while(ch!='\0')
	{
		ch=string[i++];
		cout << ch;
	}
	cout << endl << endl;
}


Do you have all your #includes and using statements?
Thanks a lot, my code works now, but now I've hit another dead end, mind helping again?
Go for it.
I'm trying to create a linked list; so far my code is:

node *newnode=new node;
newnode->item=dataItem;
newnode->next=back;
back=newnode;
//front and back are =NULL;
so far it works, but I'm not sure how to set front to be the first node.
I've tried, but it prints the first node twice:

if(isEmpty())
{
front=newnode;
back=newnode;
newnode->next=NULL;
}
else
{
newnode->next=back;
back=newnode;
}
Thanks again for reading, hoping for feedback.
I'm not familiar with linked lists.

If I were you, I'd mark this thread as "solved" and open a new one to get more eyes working on it.

:)
Topic archived. No new replies allowed.