Your biggest problems are:
- incorrect use of
scanf() adding & before word1 invoking undefined behavior. word1 is already a pointer due to array/pointer conversion. See: C11 Standard - 6.3.2.1 Other Operands - Lvalues, arrays, and function designators(p3)
- You fail to use the field-width modifier to protect your array bounds allowing the user to exploit your code by entering more characters than your array can hold. Using
scanf() with the "%s" conversion specifier without a field-width modifier to limit the input to the number of characters your array can hold is no safer than using gets(). See: Why gets() is so dangerous it should never be used!
- You loop beyond the end of your array with your
for loop if your array contains less than 9 character (which should be 11 to hold a 10 character string.) word1 (if properly read), is a nul-terminated string. You simply loop until you find the end-of-string (e.g. the '\0' character whose ASCII value is just plain-old 0). You don't loop over the max number of chars your array can hold -- they may hold values that are not set.
To correct the issues above, and more, you could do:
#include <stdio.h>
#define MAXCHR 10 /* if you need a constant, #define one (or more) */
int main (void) {
char word1[MAXCHR + 1]; /* to treat chars as a string, you need +1 for \0 */
int i;
fputs ("Enter your first word: ", stdout); /* no conversion, printf not needed */
if (scanf ("%10s", word1) != 1) { /* validate EVERY input, protect */
puts ("EOF encountered on read of word1"); /* array bounds with field-width */
return 0;
}
printf ("your word is: %s\n", word1); /* output word1 */
for (i = 0; word1[i]; i++) /* word1 is a string, loop to end */
printf ("%c ", word1[i]);
putchar ('\n'); /* tidy up with newline */
#if defined (_WIN32) || defined (_WIN64)
system("pause"); /* non-portable, only for windows */
#endif
}
(note: printf() is only needed for output if your output string contains a conversion, otherwise, puts(), or fputs() if end-of-line control is needed, are fine)
Example Use/Output
Basic input within the number of characters:
$ ./bin/word1
Enter your first word: bananas
your word is: bananas
b a n a n a s
Input of exactly the number of characters allowed:
$ ./bin/word1
Enter your first word: 1234567890
your word is: 1234567890
1 2 3 4 5 6 7 8 9 0
Input of twice as many characters as the array can hold as a string:
$ ./bin/word1
Enter your first word: 12345678901234567890
your word is: 1234567890
1 2 3 4 5 6 7 8 9 0
(note: no matter how many characters you attempt to input, only 10 plus the nul-terminating character will be stored. Be aware that any characters not read, remain in stdin unread -- just waiting to bite you on your next input. That is why input should be taken with fgets() or POSIX getline() so that the entire line of input is consumed. Regardless of which input function you use, you cannot use it correctly unless you check the return to determine if the input succeeded or failed.)
Look things over and let me know if you have further questions.