string copying

After writing the string the program crashes :(

1
2
3
4
5
6
7
8
9
10
#include<stdio.h>
#include<string.h>
char s1[8],s2[8];
int main(){
	printf("Inserisci 8 caratteri: ");
	scanf("%s",&s1);
	strcpy(s2,s1);
	printf("Ora s2 e': %s",s2);
	return 0;
}
The program can not handle words longer than 7 characters. If you input a longer word it could lead to a program crash.

The %s specifier expects a char* but &s1 gives you a pointer to the array which has type char(*)[8]. I doubt it will lead to any trouble but to be correct it should be scanf("%s",&s1[0]); or scanf("%s",s1);
it doesn't work... i tried to change the scanf and the length of the char but it doesn't work
When the program crashes, what error message do you get?
windows says that my program has finished to work
Topic archived. No new replies allowed.