char first[10];
char second[10];
What does fscanf(fr,"%s %s\n",first,second); do when first string is too long?
can I use just char *first without malloc? and the pointer will show to the string?
char first[10];
char second[10];
What does fscanf(fr,"%s %s\n",first,second); do when first string is too long?
can I use just char *first without malloc? and the pointer will show to the string?
You can use a width (i.e. "%9s") to restrict the size of the string. For example, see Microsoft's documentation.
Using a pointer without initializing it to anything is a sure way to get your program to crash, or otherwise behave badly.
When the first string is too long, you run into a problem of a buffer overflow.
As for the second part of your question, if you do not use malloc, then then it will be pointing to garbage memory. Its possible that the string will stay there for a while, but its not guaranteed, and if that memory segment is used by something else you will lose your string.
If you are using glibc, you can solve both issues in one shot - use %as
format specifier.
It will automatically allocate string big enough to hold the content.
Like this:
char *first, *second;
scanf(fp, "%as %as\n", first, second);
Note: This is GNU extension!