1、http://bbs.csdn.net/topics/330194493
char *encode=getenv("LANG"); char *search="."; //查找字符串 int pos=strcspn(encode,search); char str[1024]; //求子字符串 strncpy(str,encode+pos+strlen(search),strlen(encode)-pos); printf("%s\n",str);
int append_to_file_by_c(char *filename,char* content) { FILE *file; file=fopen(filename,"a"); if(file==NULL) { return -1; } //fseek(file, 0L, SEEK_END); fwrite(content,strlen(content),1,file); fclose(file); return 0; } int main(int argc, char **argv) { char content[1024]={0}; char time_str[1024]={0}; time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo =localtime(&rawtime); //printf("The current date/time is: %s", asctime (timeinfo)); sprintf(time_str,"%4d-%02d-%02d %02d:%02d:%02d ",1900+timeinfo->tm_year, 1+timeinfo->tm_mon, timeinfo->tm_mday,timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); //printf("%s\n",time_str); strcat_s(content,time_str); for(int i=0;i<argc;i++) { strcat_s(content,argv[i]); strcat_s(content," "); } strcat_s(content,"\n"); append_to_file_by_c("adb_log.txt",content);