{"id":281,"date":"2020-02-23T19:07:37","date_gmt":"2020-02-23T19:07:37","guid":{"rendered":"https:\/\/codesupply.co\/quis-nascetur-aenean-ipsum-vici\/"},"modified":"2022-11-12T19:20:29","modified_gmt":"2022-11-12T19:20:29","slug":"c-program-to-compare-the-two-strings","status":"publish","type":"post","link":"https:\/\/nootherjake.com\/blog\/c-program-to-compare-the-two-strings\/","title":{"rendered":"C Program to Compare the Two Strings"},"content":{"rendered":"<blockquote><p><strong>Write a program to compare two strings by passing them to a function. The function will return 1 if both the strings are the same, else it returns 0.\u00a0<\/strong><\/p><\/blockquote>\n<div>\n<div>#include&lt;stdio.h&gt;<\/div>\n<div>int stringcompare(char*,char*);<\/div>\n<div>int main()<\/div>\n<div>{<\/div>\n<div>charstr1[20]; \/\/ declaration of char array<\/div>\n<div>charstr2[20]; \/\/ declaration of char array<\/div>\n<div>printf(&#8220;Enter the first string : &#8220;);<\/div>\n<div>scanf(&#8220;%s&#8221;,str1);<\/div>\n<div>printf(&#8220;\\nEnter the second string : &#8220;);<\/div>\n<div>scanf(&#8220;%s&#8221;,str2);<\/div>\n<div>intcompare=stringcompare(str1,str2); \/\/ calling stringcompare() function.<\/div>\n<div>if(compare==0)<\/div>\n<div>printf(&#8220;strings are equal&#8221;);<\/div>\n<div>else<\/div>\n<div>printf(&#8220;strings are not equal&#8221;);<\/div>\n<div>return 0;<\/div>\n<div>}<\/div>\n<div>\/\/ Comparing both the strings using pointers<\/div>\n<div>int stringcompare(char *a,char *b)<\/div>\n<div>{<\/div>\n<div>intflag=0;<\/div>\n<div>while(*a!=&#8217;\\0&#8242; &amp;&amp; *b!=&#8217;\\0&#8242;) \/\/ while loop<\/div>\n<div>{<\/div>\n<div>if(*a!=*b)<\/div>\n<div>{<\/div>\n<div>flag=1;<\/div>\n<div>}<\/div>\n<div>a++;<\/div>\n<div>b++;<\/div>\n<div>}<\/div>\n<div><\/div>\n<div>if(flag==0)<\/div>\n<div>return0;<\/div>\n<div>else<\/div>\n<div>return1;<\/div>\n<div>}<\/div>\n<\/div>\n<figure id=\"attachment_4352\" aria-describedby=\"caption-attachment-4352\" style=\"width: 3360px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4352\" src=\"https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings.png\" alt=\"Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C \" width=\"3360\" height=\"2100\" srcset=\"https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings.png 3360w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-300x188.png 300w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-1024x640.png 1024w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-768x480.png 768w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-1536x960.png 1536w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-2048x1280.png 2048w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-380x238.png 380w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-800x500.png 800w, https:\/\/nootherjake.com\/blog\/wp-content\/uploads\/2020\/02\/C-Program-to-Compare-the-Two-Strings-1160x725.png 1160w\" sizes=\"auto, (max-width: 3360px) 100vw, 3360px\" \/><figcaption id=\"caption-attachment-4352\" class=\"wp-caption-text\">Buffer Overflow Attack Real-life Example, Buffer Overflow C, Buffer Overflow C Example, Buffer Overflow Code Injection Example, Buffer Overflow Command Line, Buffer Overflow Example, How To Avoid Buffer Overflow In C, How To Check Buffer Overflow In C.<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"Write a program to compare two strings by passing them to a function. The function will return 1 if both the strings are the same, else it returns 0. \n","protected":false},"author":1,"featured_media":4353,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"csco_singular_sidebar":"default","csco_page_header_type":"large_overlay","csco_page_load_nextpost":"default","csco_post_video_location":[],"csco_post_video_url":"","csco_post_video_bg_start_time":0,"csco_post_video_bg_end_time":0,"footnotes":""},"categories":[3],"tags":[32,33,34,35,36,37,38,39],"class_list":{"0":"post-281","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-incident-response","8":"tag-buffer-overflow-attack-real-life-example","9":"tag-buffer-overflow-c","10":"tag-buffer-overflow-c-example","11":"tag-buffer-overflow-code-injection-example","12":"tag-buffer-overflow-command-line","13":"tag-buffer-overflow-example","14":"tag-how-to-avoid-buffer-overflow-in-c","15":"tag-how-to-check-buffer-overflow-in-c","16":"cs-entry","17":"cs-video-wrap"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/posts\/281","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/comments?post=281"}],"version-history":[{"count":4,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":4356,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/posts\/281\/revisions\/4356"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/media\/4353"}],"wp:attachment":[{"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/media?parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/categories?post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nootherjake.com\/blog\/wp-json\/wp\/v2\/tags?post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}