Jump to content

Cant display full character array

- - - - -

  • Please log in to reply
1 reply to this topic

#1
kramman

kramman

    Newbie

  • Members
  • Pip
  • 1 posts
i was having an issue earlier with my program displaying garbage but i think i figured out that problem. my program gets 3 pieces of info a "tracking number" a "description" and a "price". my issue is when trying to display the description from my linked list it only displays the first letter of the array. i dont know what im doing wrong.




#include <iostream>

#include <string>

#include <iomanip>

using namespace std;



struct node

{

	float TrackNum;

	char Desc[35];

	double Charge;

	node *link; //pointer to the next record


};


node* HeadPointer = NULL;


void InsertItem ( float, char [35], double, node * );

void PrintList (node * );


int main()

{


	char ContFlag = 'Y';

	float InitTrackNum = '\0'; 

	char InitDesc[35] = "\0";

	double InitCharge = '\0';

	node* CurrentRecordPointer = NULL;


	char NextChar = '\0';


	while (toupper(ContFlag) == 'Y')

	{


		//Getting tracking number

		cout << "Enter tracking number: ";

		cin >> InitTrackNum;

		cout << endl;


		//Getting Description

		cout << "Enter Description: ";


		NextChar = cin.peek();

		

		if (NextChar == '\n' )

		{

			cin.ignore();

		}


		cin.get(InitDesc, 35);

		cout << endl;


		//Getting charge

		cout << "Enter charge: ";

		cin >> InitCharge;

		cout << endl;


		CurrentRecordPointer = new node;


		InsertItem( InitTrackNum, InitDesc, InitCharge, CurrentRecordPointer);

		HeadPointer = CurrentRecordPointer;



		cout << "Do you wish to enter more data? ( 'Y' or 'N' ) ";

		cin>> ContFlag;


	}


	cout << endl << endl;

	

	PrintList (HeadPointer); //sending what ever variable represents the head of the list


return 0;


}//end of main


//insert data into the linked list and set link to next node

void InsertItem (float InitTrackNum, char* InitDesc, double InitCharge, node *CurrentRecordPointer)

{

	

	CurrentRecordPointer->TrackNum = InitTrackNum;

	CurrentRecordPointer->Desc[35] = *InitDesc;

	CurrentRecordPointer->Charge = InitCharge;

	CurrentRecordPointer->link = HeadPointer;

	

	


	

	

}


void PrintList (node *Head)

{

	cout << setw(12)<<left<<"Tracking"<<setw(35)<<left<<"Type of Animal"<<setw(14)<<left<<"Daily Boarding"<<endl;

	cout <<	setw(12)<<left<<"Number"<<setfill(' ')<<setw(35)<<" "<<setw(14)<<left<<"Charge"<<endl;

	cout << setw(60)<< setfill('-')<<" "<<endl;

	cout << setfill(' ');


	while (Head != NULL )

	{

		cout <<setw(12)<<left<< Head->TrackNum << setw(35) << Head->Desc[35] << setw(14) << Head->Charge << endl;

		Head = Head->link;

	}


}




#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
In PrintList(), change Head->Desc[32] to just Head->Desc.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users