length of a char array in c
char chararray[10];
size_t len = strlen(chararray);
length of a char array in c
char chararray[10];
size_t len = strlen(chararray);
how to check the word is present in given char array in c
#include <stdio.h>
int main()
{
char c_to_search[5] = "asdf";
char text[68] = "hello my name is \0 there is some other string behind it \n\0 asdf";
int pos_search = 0;
int pos_text = 0;
int len_search = 4;
int len_text = 67;
for (pos_text = 0; pos_text < len_text - len_search;++pos_text)
{
if(text[pos_text] == c_to_search[pos_search])
{
++pos_search;
if(pos_search == len_search)
{
// match
printf("match from %d to %d\n",pos_text-len_search,pos_text);
return;
}
}
else
{
pos_text -=pos_search;
pos_search = 0;
}
}
// no match
printf("no match\n");
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us