#include <iostream>
using namespace std;

typedef struct List {
	int data;
	List*link;
	List(){
		data=0;
		link=NULL;}
}SList;
SList*L,*P,*temp;
int x;

SList*createnew(int x){
	temp=new List;		
	temp->data = x;
	temp->link = NULL;
	
	return (temp);
}

SList*findLast(SList*L){
	temp=L;
	while(temp->link != NULL)
		temp=temp->link;
	return (temp);
}

void printList(SList*L){
	temp=L;
	while(temp!= NULL){
		cout<<temp->data<<endl;
		temp=temp->link;
	}
}

int count(SList*L){
	temp=L;
	int i=0;
	while (temp != NULL){
		i++;
		temp=temp->link;
	}
	return (i);
}

void addend (){
	L=NULL;
	cout<<"Please enter a number "; cin>>x;
	do{
		
		if(cin.eof())
			break;
		P=createnew(x);
		if(L!=NULL){
			temp=findLast(L);
			temp->link=P;}
		else
			L=P;
		cout<<"Please enter a number ";
	}while ( cin>>x);

}

int main(){
	addend();
	printList(L);

	return 0;
}

Why i must enter ctrl+z 2 times to out from the loop..?

worked ok for me using VC++ 2008 Express on Vista Home Premium. I had to press Ctrl+Z followed by <Enter> keys.

Same here, using GCC and XP.

>Why i must enter ctrl+z 2 times to out from the loop..?
The Windows shell has trouble handling EOF properly unless it's the first character on the line. Most likely you're doing something like this:

this is a test^Z
^Z

The program only stops at the second ^Z because the first is preceded by valid characters before a newline. If you want portable code you just have to suffer with it, but you can also perform a workaround because the first ^Z is typically treated as a legitimate character and will be returned by the input function. You can take advantage of that by testing for the specific character value on top of the standard EOF mechanism:

#include <iostream>

#define CTRLZ 0x1A

int main()
{
  char ch;

  while ( std::cin.get ( ch ) && ch != CTRLZ )
    std::cout<< ch <<": "<< int ( ch ) <<'\n';
}

Actually i'm using visual C++..After heard all the comment, i'm trying dev-C++..Actually the code is working well..Thanx for all..

>After heard all the comment, i'm trying dev-C++..
You're not likely to see a difference with that particular problem as long as it's a Windows compiler.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.