小编Rhu*_*umB的帖子

Simpledataformat无法识别有效字符串

  public static boolean checkTimeFormat(String str){

    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.parse(str);
        return true;
    } catch (ParseException ex) {
        System.out.println("not a valid time:"+str);
        //ex.printStackTrace();
    }

return false;
}
Run Code Online (Sandbox Code Playgroud)

我有这个方法来检查str是否以正确的格式进行了测试

 2015–01-01 07:01:14
Run Code Online (Sandbox Code Playgroud)

它说不是一个有效的时间.我很困惑,因为它们的格式相同.

java simpledateformat

4
推荐指数
1
解决办法
58
查看次数

C在使用scanf时动态分配struct,seg fault

#include <stdio.h>  
#include <stdlib.h>
struct Person {
  char* name;
  int age;
};

void printit(struct Person *person) {
    printf("%s %d \n",person->name,person->age);
}

int main(int argc, char** argv) {
  struct Person *p = malloc(sizeof(struct Person));
  printf("Enter name: ");
  scanf("%s", p->name);
  printf("Enter age: ");
  scanf("%d", &(p->age));
  printit(p);
  free(p);
}
Run Code Online (Sandbox Code Playgroud)

输入名称:asdf

分段错误:11

我不知道为什么它会给出分段错误....

c struct scanf segmentation-fault

0
推荐指数
1
解决办法
115
查看次数

标签 统计

c ×1

java ×1

scanf ×1

segmentation-fault ×1

simpledateformat ×1

struct ×1