I need to write c program to compare two strings without using strncpy() and then in another funtion check whether it works with using assert()
In my code by checking with pointers assert(*str2 == *"comp");
I only check the first letter and nothing else.So even there is another word starting with c, it will work.
char initialize_n(char str1[], char str2_n[], int n)
{
//initialize a string from the (at most) n first characters of another string
int i = 0;
for(i = 0; i < n; i++)
{
str2_n[i] = str1[i];
}
str2_n[i] = '\0';
}
void test_initialize_n(){
char str1[100] = "computer";
char str2[100];
initialize_n(str1, str2, 4);
assert(*str2 == *"comp");
}
How to correctly check it with assert?