Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 7, 2008, 12:36 PM   #1
jamesapp
macrumors 6502a
 
Join Date: Mar 2008
pointerproblems

james-collinss-macbook-prorog13 jamescollins$ ./prog13.10
Today's date is 9/25/.24.

got this output when i tried to run a program from a book.

here is my test program which i called prog13.10.m

[code]
// program to illustrate structure pointers
#import <stdio.h>

int main (int argc, char *argv[])
{
struct date
{
int month;
int day;
int year;

};

struct date today, *datePtr;

datePtr = &today;
datePtr ->month = 9;
datePtr ->day = 25;
datePtr ->year = 2004;

printf ("Today's date is %i/%i/.2%i. \n",
datePtr->month, datePtr->day, datePtr->year %100);
return 0;

}
[code]

for the year my program says .24 instead of 04
any help would be appreciated.
jamesapp is offline   0 Reply With Quote
Old Apr 7, 2008, 12:50 PM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by jamesapp View Post
[code]
printf ("Today's date is %i/%i/.2%i. \n",
datePtr->month, datePtr->day, datePtr->year %100);
[code]

for the year my program says .24 instead of 04
any help would be appreciated.
Your code writes the month in format %i, followed by a slash, followed by the day in format %i, followed by the text "/.2", followed by year modulo 100 in format %i. Maybe you meant %.2i.
gnasher729 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Forum Jump

All times are GMT -5. The time now is 04:12 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC