Compare 2 Strings in C

Compare two strings in C :

#include<stdio.h>

#include<string.h>
#include<stdbool.h>

int main()
{
char str1[] = "ABC";
char str2[] = "ABC";

bool res;
int i=0;
while(str1[i] != '\0' && str2[i] != '\0')
{
if(str1[i] == str2[i])
res = false;
else
res = true;

i++;
}

printf("%d\n", res);
return 0;
}




Comments

Popular posts from this blog

Setting up a USB thermal printer with a Raspberry Pi 3B+

Autostart an app on reboot - Raspberry Pi

Basic Input/Output C Program