C
crovax75
LS,
I've a problem to get the year, month and day from the following
string: "20051027"
--
#include <stdio.h>
#include <string.h>
char str[9]="20051027";
char year[5], month[3], day[3];
int main(void){
printf("String str: %s\n",str);
strncpy(year, str, 4);
year[4] = '\0';
printf("%s\n", year);
//But how to get the month in the string 'str'?
printf("Year:%s\n",year);
printf("Month:%s\n",month);
printf("Day:%s\n",day);
getchar();
return 0;
}
--
PS. It is not a problem to concert it to integers.
Greetz,
Marcel
I've a problem to get the year, month and day from the following
string: "20051027"
--
#include <stdio.h>
#include <string.h>
char str[9]="20051027";
char year[5], month[3], day[3];
int main(void){
printf("String str: %s\n",str);
strncpy(year, str, 4);
year[4] = '\0';
printf("%s\n", year);
//But how to get the month in the string 'str'?
printf("Year:%s\n",year);
printf("Month:%s\n",month);
printf("Day:%s\n",day);
getchar();
return 0;
}
--
PS. It is not a problem to concert it to integers.
Greetz,
Marcel