Не потому, что это будет лучше, чем ответ Эндрю, а потому, что все предупреждения, которые gcc
дает мне ваш код, не вписываются в комментарий.
/usr/bin/gcc -c -o str.o str.c
str.c: In function 'insert':
str.c:53: warning: format '%c' expects type 'char *', but argument 2 has type 'char (*)[30]'
str.c:57: warning: incompatible implicit declaration of built-in function 'strcpy'
str.c: In function 'print':
str.c:79: warning: format '%c' expects type 'int', but argument 2 has type 'char *'
gcc
должно бытьВы предупреждение о "неявном объявлении", не игнорируйте такие вещи.Более того, используйте c99 и опцию -Wall, чтобы получить больше предупреждений, а затем исправьте их все.
c99 -Wall -c -o str.o str.c
str.c: In function 'main':
str.c:30: warning: unused variable 'p'
str.c: In function 'insert':
str.c:52: warning: format '%c' expects type 'char *', but argument 2 has type 'char (*)[30]'
str.c:56: warning: implicit declaration of function 'strcpy'
str.c:56: warning: incompatible implicit declaration of built-in function 'strcpy'
str.c:49: warning: unused variable 'junk'
str.c:48: warning: unused variable 'num'
str.c: In function 'print':
str.c:78: warning: format '%c' expects type 'int', but argument 2 has type 'char *'
str.c:81: warning: 'return' with no value, in function returning non-void