Thread: How to make char array accept spaces

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    1

    Talking How to make char array accept spaces

    Hi
    I've created a program for my final project entitled 'Video Rental System'. I used linked list and the output is saved into an external file (*.txt). Some of the functions are Add New Video, Delete Video, Display List of Videos etc.

    The problem is, whenever the display function is called, it will only display one word only. But in the *.txt file it is a full word. For example, if i key in 'Lord of The Rings' for video's title, it will only be 'Lord' when display function is called. But in *.txt file, it is 'Lord of The Rings'. Should i use string? Need some help pls

    Code:
    ***** Add new video function *****
    
    void List::AddVideo() // method add video dlm linked list
    {
    		int code;
    		char category[20];
    		char title[40];
    		
    		Node *newNode = new Node;
    
    	cout<<" Enter video's code : ";
    	cin>>code;
    	newNode->Code=code;
    
    	cout<<" Enter video's category : ";
    	cin.ignore();
    	cin.getline(category,20,'\n');
    //	cin>>category;
    	strcpy(newNode->Category,category);
    
    	cout<<" Enter video's title : ";
    	cin.getline(title,40,'\n');
    //	cin>>title;
    	strcpy(newNode->Title,title);
    
    	cout<<" \n New video has been added";
    
    	newNode->link=head;
    	head=newNode;
    
    	if (no_of_node == 0)
    		tail = newNode;
    	no_of_node++;
    
    	ofstream OutputFile("Record.txt",ios::app); // output data dlm "Record.txt"
    
    	Node *current = head;
    	OutputFile<<current->Code<<setw(22)<<current->Category<<setw(21)<<current->Title;
    	OutputFile<<endl;
    }
    
    ***** Display function *****
    
    void List::Display() //method display list
    {
    	char pause;
    	Node *current = head;
    
    	cout<<" CODE"<<setw(17)<<" CATEGORY"<<setw(17)<<" TITLE\n"<<endl;
    	
    	while (current !=0)
    	{
    		cout<<" "<<current->Code<<setw(17)<<current->Category<<setw(17)<<current->Title<<endl;
    		current = current->link;
    	}
    	cout<<"\n";
    }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-17-2008, 12:36 PM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  4. Strings are V important...
    By NANO in forum C++ Programming
    Replies: 15
    Last Post: 04-14-2002, 11:57 AM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM