From 3d67d1eee9dcdc58b38e243f7ffa0aca43b61147 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Tue, 16 Mar 2021 00:50:10 -0400 Subject: [PATCH] simplify --- src/variable.cpp | 8 ++------ src/write_coeff.cpp | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/variable.cpp b/src/variable.cpp index 79543f9a71..1af4a4728a 100644 --- a/src/variable.cpp +++ b/src/variable.cpp @@ -186,9 +186,7 @@ void Variable::set(int narg, char **arg) nlast = utils::inumeric(FLERR,arg[2],false,lmp); if (nlast <= 0) error->all(FLERR,"Illegal variable command"); if (narg == 4 && strcmp(arg[3],"pad") == 0) { - char digits[12]; - sprintf(digits,"%d",nlast); - pad[nvar] = strlen(digits); + pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; } else if (narg == 4 || (narg == 5 && strcmp(arg[4],"pad") == 0)) { nfirst = utils::inumeric(FLERR,arg[2],false,lmp); @@ -196,9 +194,7 @@ void Variable::set(int narg, char **arg) if (nfirst > nlast || nlast < 0) error->all(FLERR,"Illegal variable command"); if (narg == 5 && strcmp(arg[4],"pad") == 0) { - char digits[12]; - sprintf(digits,"%d",nlast); - pad[nvar] = strlen(digits); + pad[nvar] = fmt::format("{}",nlast).size(); } else pad[nvar] = 0; } else error->all(FLERR,"Illegal variable command"); num[nvar] = nlast; diff --git a/src/write_coeff.cpp b/src/write_coeff.cpp index 8f1f6140ed..485bc3b29b 100644 --- a/src/write_coeff.cpp +++ b/src/write_coeff.cpp @@ -43,11 +43,7 @@ void WriteCoeff::command(int narg, char **arg) if (narg != 1) error->all(FLERR,"Illegal write_coeff command"); - int n = strlen(arg[0]) + 5; - char *file = new char[n]; - - strcpy(file,"tmp."); - strcat(file,arg[0]); + char *file = utils::strdup(fmt::format("tmp.{}",arg[0])); // initialize relevant styles lmp->init(); @@ -114,7 +110,7 @@ void WriteCoeff::command(int narg, char **arg) const char *section = (const char *)""; fputs(str,two); // style utils::sfgets(FLERR,str,256,one,file,error); // coeff - n = strlen(str); + int n = strlen(str); strcpy(coeff,str); coeff[n-1] = '\0'; utils::sfgets(FLERR,str,256,one,file,error);