Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can int data be converted to char data

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I believe atoi() would be used, but how?


struct CarType
{
char MFG;
char Model;
char Color;
char TransType;
char Doors;
char Year;
}

cout<<&quot;Vehicle must be a 1980 or newer vehicle to enter the program: &quot;<<endl;
cout<<&quot;Enter the vehicle year: &quot;;
cin>>vehYear;

if ( vehYear >= 1980 || vehyear <= 2002)
strcpy(CarType.Year, vehYear)

// I am not sure how to convert the int data to char data.
// I need it to begin as int data so I can validate the year data before copying.


// Any help would be great!!

 
CarType.Year = (char)vehYear;

or if you want to convert &quot;vehYear&quot; to a string, you can use this:
#include<stdlib.h>
.....
...
char buffer[6];
_itoa( vehYear, buffer, 10 )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top