The first thing to notice is that technically, it can be argued that "bea" is fully contained in "beautiful" in the sense that all the letters are there in sequence and next to each other: I would expect to find "true" for that.
And when I run your code with "beautiful" and "bea" I get
false
anyway ...
As I do for "beautiful" and "eau", which is wrong, and for "beautiful" and "aut", but not for "beautiful" and "auti" which returns true.
That code is a bad way to do it: your are copying a lot of information just so you can use standard functions, and that is part of your problem. Read the definition of
strncpy[
^] and then think about what it puts in your sub1 buffer, and what
strcmp[
^] is going to do with it.
This is your homework: while I wouldn't do it like this (it's very inefficient) it's also t=your task to get it working. So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.
Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
Oh, and do yourself a favour: indent your code! It becomes a lot more readable, and easier to work with if you do that...
#include <stdio.h>
#include <string.h>
int
main (int argc, char **argv)
{
char *str1, *str2;
int str1len, str2len;
str1 = argv[1];
str2 = argv[2];
str1len = strlen (str1);
str2len = strlen (str2);
if (str2len > str1len)
{
printf ("false\n");
return 0;
}
char sub1[100];
for (int i = 0; i < str1len - str2len; i++)
{
strncpy (sub1, str1 + i, str2len);
if (strcmp (sub1, str2) == 0)
{
printf ("true\n");
return 0;
}
}
printf ("false\n");
return 0;
}
See what I mean?