たとえば、有効なURLを検証するために、私は次のよう文字列がCで特定の文字列で始まるかどうかを確認する方法は?
char usUrl[MAX] = "http://www.stackoverflow"
if(usUrl[0] == 'h'
&& usUrl[1] == 't'
&& usUrl[2] == 't'
&& usUrl[3] == 'p'
&& usUrl[4] == ':'
&& usUrl[5] == '/'
&& usUrl[6] == '/') { // what should be in this something?
printf("The Url starts with http:// \n");
}
それとも、私はstrcmp(str, str2) == 0
を使用してについて考えてきましたが、これは非常に複雑でなければならない操作を行いたいと思います。
このようなことをする標準的なC関数はありますか?
'strncmp'を試してみてください。 – congusbongus
の可能な複製[startWith(str \ _a、str \ _b)\ 'Cのような何か?](http://stackoverflow.com/questions/4770985/something-like-startswithstr-a-str-b- in-c) –