سلام دوستان
این برنامه :NO: چرا درست کار نمیکنه؟؟
[code=c]
#include <mega128a.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void test();
char str1[]="abcd20151011";
char Year[], Month[], Day[];
int Year_int, Month_int, Day_int;
void main()
{
char str2[];
// USART Settings
UCSR0A = 0x00;
UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0 );
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
UBRR0H = 0x00;
UBRR0L = 0x05;
#asm("sei"
test();
sprintf(str2,"%04d/%02d/%02d",Year_int,Month_int,Day_int);
printf("data=%s",str2);
while(1);
}
void test()
{
Year[0] = '2';
Year[1] = '0';
Year[2] = str1[6];
Year[3] = str1[7];
Month[0] = str1[8];
Month[1] = str1[9];
Day[0] = str1[10];
Day[1] = str1[11];
Year_int = atoi(Year);
Month_int = atoi(Month);
Day_int = atoi(Day);
}
[/code]
میخوام اینجوری نشون بده: data=2015/10/11
ولی اینجوری نشون میده:

فایل کدویژن + پروتئوس:
http://s6.picofile.com/file/8226168800/saman.rar.html
این برنامه :NO: چرا درست کار نمیکنه؟؟
[code=c]
#include <mega128a.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void test();
char str1[]="abcd20151011";
char Year[], Month[], Day[];
int Year_int, Month_int, Day_int;
void main()
{
char str2[];
// USART Settings
UCSR0A = 0x00;
UCSR0B = (1<<RXCIE0)|(1<<RXEN0)|(1<<TXEN0 );
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);
UBRR0H = 0x00;
UBRR0L = 0x05;
#asm("sei"

test();
sprintf(str2,"%04d/%02d/%02d",Year_int,Month_int,Day_int);
printf("data=%s",str2);
while(1);
}
void test()
{
Year[0] = '2';
Year[1] = '0';
Year[2] = str1[6];
Year[3] = str1[7];
Month[0] = str1[8];
Month[1] = str1[9];
Day[0] = str1[10];
Day[1] = str1[11];
Year_int = atoi(Year);
Month_int = atoi(Month);
Day_int = atoi(Day);
}
[/code]
میخوام اینجوری نشون بده: data=2015/10/11
ولی اینجوری نشون میده:

فایل کدویژن + پروتئوس:
http://s6.picofile.com/file/8226168800/saman.rar.html
دیدگاه