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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pointers problem

Status
Not open for further replies.

FoxStudent

Technical User
Feb 24, 2000
85
GB
I have a character array in the form DD/MM/YYYY and want to reference the last four characters as an integer. I could not find a 'right' function. So I strated trying to address individual elements, for example, date[6] when printing the result to the screen I got the character numeral. However, it appears to see the character as an integer I have tried using the char() function and this seems not to work in an assignmentent statement as it still sees the new character as an integer and I cannot get it to convert to a character pointer. I need a charcter pointer in order to concatencate the last four letters so as I can convert them all into an integer. I am sure there is an easier way to do this.
P.S. this is a stored date I am aware of the getdate() function for getting the current date in terms of day, month and year.

THANK U
GRAINNE
 
Well, knowing that it will always be in the DD/MM/YYYY format you can do a couple of things. Here is how I would approach it.

Code:
// check this quick snip of code that accomplishes what you
// need

char dateString[]= "01/03/2001";
char tempString[11];
strcpy(tempString,dateString);

char* dayPtr;
char* monthPtr;
char* yearPtr;

dayPtr = tempString;

monthPtr = strstr(dayPtr,"/")+1;
*(monthPtr-1)=0;

yearPtr = strstr(monthPtr,"/")+1;
*(yearPtr-1) = 0;

cout<<atoi(dayPtr)<<endl;
cout<<atoi(monthPtr)<<endl;
cout<<atoi(yearPtr)<<endl;
 
How about this

String sDate = DateToStr(Date());
sDate = sDate.SubString(7,4);
int iDate = StrToInt(sDate);

A variation of the above code should get you what you need.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top