
{"id":19048,"date":"2022-08-02T21:39:53","date_gmt":"2022-08-02T16:09:53","guid":{"rendered":"https:\/\/beautifulworknew.wordpress.com\/?p=19048"},"modified":"2022-08-02T21:39:53","modified_gmt":"2022-08-02T16:09:53","slug":"check-for-numeric-value-in-a-string-and-do-conversion","status":"publish","type":"post","link":"https:\/\/www.trueangle.org\/index.php\/2022\/08\/02\/check-for-numeric-value-in-a-string-and-do-conversion\/","title":{"rendered":"Check if a string has only numerals and do conversion if  it is true"},"content":{"rendered":"\n<pre class=\"wp-block-preformatted\">$ls\nascii-table     avg-with-garbage.txt  env-var.c      functions_ver1    mph-to-kph\nascii-table.c   case-changer          env-var-set    functions_ver1.c  mph-to-kph.c\nascii-table.md  case-changer.c        env-var-set.c  functions_ver2    mph-to-kph_v2.c\navg.txt         env-var               exist.sh       functions_ver2.c  output.c\n$.\/mph-to-kph \n564\n907.7\n$cat mph-to-kph.c \n#include &lt;stdio.h&gt;\n#include &lt;stdlib.h&gt;\n#include &lt;string.h&gt;\n\nint main(void)\n{\n    char mph[10] = { 0 };\n\n    while(fgets(mph, sizeof(mph), stdin) != NULL)\n    {\n        \/* Check if mph is numeric \n         * (and do conversion) *\/\n        if( strspn(mph, \"0123456789.-\\n\") == \n            strlen(mph) )\n        {\n            printf(\"%.1f\\n\", (atof(mph)*1.60934) );\n        }\n        \/* If mph is NOT numeric, print error \n         * and return *\/\n        else\n        {\n            fprintf(stderr, \"Found non-numeric\" \n                \" value\\n\");\n            return 1;\n        }\n    }\n    return 0;\n}\n$\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>$ls ascii-table avg-with-garbage.txt env-var.c functions_ver1 mph-to-kph ascii-table.c case-changer env-var-set functions_ver1.c mph-to-kph.c ascii-table.md case-changer.c env-var-set.c functions_ver2 mph-to-kph_v2.c avg.txt env-var exist.sh functions_ver2.c output.c $.\/mph-to-kph 564 907.7 $cat mph-to-kph.c #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; int main(void) { char mph[10] = { 0 }; while(fgets(mph, sizeof(mph), stdin) != NULL) { \/* Check if mph is numeric * (and &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.trueangle.org\/index.php\/2022\/08\/02\/check-for-numeric-value-in-a-string-and-do-conversion\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Check if a string has only numerals and do conversion if  it is true&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19048"}],"collection":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/comments?post=19048"}],"version-history":[{"count":0,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/posts\/19048\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/media?parent=19048"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/categories?post=19048"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.trueangle.org\/index.php\/wp-json\/wp\/v2\/tags?post=19048"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}