{"id":27188,"date":"2017-06-01T19:28:39","date_gmt":"2017-06-01T13:58:39","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=27188"},"modified":"2017-06-01T19:28:39","modified_gmt":"2017-06-01T13:58:39","slug":"c-program-remove-spaces-or-blanks-from-a-string","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/c-program-remove-spaces-or-blanks-from-a-string\/","title":{"rendered":"C program remove spaces or blanks from a string"},"content":{"rendered":"<p>C program remove spaces or blanks from a string, For example consider the string<\/p>\n<pre>\"c  programming\"<\/pre>\n<p>There are two spaces in this <a href=\"https:\/\/www.wikitechy.com\/technology\/substring-in-c-programming\/\">string<\/a>, so our program will print a string<\/p>\n<p>\u201cc programming\u201d. It will remove spaces when they occur more than one time consecutively in string anywhere.<\/p>\n[ad type=\u201dbanner\u201d]\n<h2 id=\"c-programming-code\">C programming code<\/h2>\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20text%5B1000%5D%2C%20blank%5B1000%5D%3B%0A%20%20%20int%20c%20%3D%200%2C%20d%20%3D%200%3B%0A%20%0A%20%20%20printf(%22Enter%20some%20text%5Cn%22)%3B%0A%20%20%20gets(text)%3B%0A%20%0A%20%20%20while%20(text%5Bc%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20if%20(text%5Bc%5D%20%3D%3D%20\u2019%20\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20int%20temp%20%3D%20c%20%2B%201%3B%0A%20%20%20%20%20%20%20%20%20if%20(text%5Btemp%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20while%20(text%5Btemp%5D%20%3D%3D%20\u2019%20\u2019%20%26%26%20text%5Btemp%5D%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(text%5Btemp%5D%20%3D%3D%20\u2019%20\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20temp%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20blank%5Bd%5D%20%3D%20text%5Bc%5D%3B%0A%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%20%20%20d%2B%2B%3B%0A%20%20%20%7D%0A%20%0A%20%20%20blank%5Bd%5D%20%3D%20\u2019%5C0\u2019%3B%0A%20%0A%20%20%20printf(%22Text%20after%20removing%20blanks%5Cn%25s%5Cn%22%2C%20blank)%3B%0A%20%0A%20%20%20return%200%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n<p>If you want you can copy blank into text string so that original string is modified.<\/p>\n<p><strong>Output of program:<\/strong><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter size-full wp-image-27193\" src=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/06\/remove-spaces-c.png\" alt=\"C program remove spaces or blanks from a string\" width=\"437\" height=\"129\" srcset=\"https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/06\/remove-spaces-c.png 437w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/06\/remove-spaces-c-300x89.png 300w, https:\/\/www.wikitechy.com\/technology\/wp-content\/uploads\/2017\/06\/remove-spaces-c-434x129.png 434w\" sizes=\"(max-width: 437px) 100vw, 437px\" \/><\/p>\n<h2 id=\"c-programming-code-using-pointers\">C programming code using pointers<\/h2>\n[ad type=\u201dbanner\u201d]\n[pastacode lang=\u201dc\u201d manual=\u201d%23include%20%3Cstdio.h%3E%0A%23include%20%3Cstring.h%3E%0A%23include%20%3Cstdlib.h%3E%0A%23define%20SPACE%20\u2019%20\u2019%0A%20%0Achar%20*process(char*)%3B%0A%20%0Aint%20main()%0A%7B%0A%20%20%20char%20text%5B1000%5D%2C%20*r%3B%0A%20%0A%20%20%20printf(%22Enter%20a%20string%5Cn%22)%3B%0A%20%20%20gets(text)%3B%0A%20%0A%20%20%20r%20%3D%20process(text)%3B%0A%20%0A%20%20%20printf(%22%5C%22%25s%5C%22%5Cn%22%2C%20r)%3B%0A%20%0A%20%20%20free(r)%3B%20%20%20%20%20%0A%20%0A%20%20%20return%200%3B%0A%7D%0A%20%0Achar%20*process(char%20*text)%20%7B%0A%20%20%20int%20length%2C%20c%2C%20d%3B%0A%20%20%20char%20*start%3B%0A%20%0A%20%20%20c%20%3D%20d%20%3D%200%3B%0A%20%0A%20%20%20length%20%3D%20strlen(text)%3B%0A%20%0A%20%20%20start%20%3D%20(char*)malloc(length%2B1)%3B%0A%20%0A%20%20%20if%20(start%20%3D%3D%20NULL)%0A%20%20%20%20%20%20exit(EXIT_FAILURE)%3B%0A%20%0A%20%20%20while%20(*(text%2Bc)%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20if%20(*(text%2Bc)%20%3D%3D%20\u2019%20\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20int%20temp%20%3D%20c%20%2B%201%3B%0A%20%20%20%20%20%20%20%20%20if%20(*(text%2Btemp)%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20while%20(*(text%2Btemp)%20%3D%3D%20\u2019%20\u2019%20%26%26%20*(text%2Btemp)%20!%3D%20\u2019%5C0\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(*(text%2Btemp)%20%3D%3D%20\u2019%20\u2032)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20temp%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20*(start%2Bd)%20%3D%20*(text%2Bc)%3B%0A%20%20%20%20%20%20c%2B%2B%3B%0A%20%20%20%20%20%20d%2B%2B%3B%0A%20%20%20%7D%0A%20%20%20*(start%2Bd)%3D%20\u2019%5C0\u2019%3B%0A%20%0A%20%20%20return%20start%3B%0A%7D\u201d message=\u201d\u201d highlight=\u201d\u201d provider=\u201dmanual\u201d\/]\n","protected":false},"excerpt":{"rendered":"<p>C program remove spaces or blanks from a string &#8211; C Programming &#8211; There are two spaces in this string, so our program will print a string.<\/p>\n","protected":false},"author":2,"featured_media":27213,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69866],"tags":[81112,81114,81113,81108,81106,81110,81116,81111,81107,81115,81117,81105,81109,81104],"class_list":["post-27188","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-programming","tag-c-program-remove-spaces","tag-c-program-remove-spaces-blanks-from-a-string","tag-c-program-to-remove-spaces-in-a-string","tag-c-program-to-remove-white-spaces-from-file","tag-how-to-print-a-string-without-spaces-in-c","tag-program-to-remove-spaces-in-a-string-in-java","tag-python-remove-spaces-from-string","tag-remove-space-from-string-in-excel","tag-remove-space-from-string-java","tag-remove-spaces","tag-remove-spaces-from-text","tag-removing-spaces-from-a-string-c","tag-trim-function-in-c","tag-write-a-c-program-to-remove-the-unnecessary-spaces-in-a-given-sentence"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/27188","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=27188"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/27188\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/27213"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=27188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=27188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=27188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}