【解决了一半】incompatible implicit declaration of built-in function ‘printf’ [enabled
老谭的教程,第七章第20个例题:7-20一个程序分为四个源文件,分别为file1.c file2.c file3.c file4.c
file1.c
1 # include <stdio.h>
2 # include <string.h>
3 # include <unistd.h>
4
5 int main(void)
6 {
7 extern void enter_string(char str[]);
8 extern void delete_string(char str[], char ch);
9 extern void print_string(char str[]);
10
11 char c;
12 char str[80];
13
14 printf("please enter a string!\n");
15 enter_string(str);
16 printf("请输入一个需要匹配的字符!\n");
17 scanf("%c", &c);
18 printf("删除字符后的字符串如下:\n");
19 delete_string(str, c);
20 print_string(str);
21
22 return 0;
23 }
file2.c
1 void enter_string(char str[80])
2 {
3 gets(str);
4
5 return ;
6 }
file3.c
1 void delete_string(char str[], char ch)
2 {
3 int i, j;
4
5 for (i = j = 0; str[i] != '\0'; i++)
6 {
7 if (str[i] != ch)
8 {
9 str[j++] = str[i];
10 }
11 }
12
13 str[j] = '\0';
14
15 return ;
16 }
file4.c
1 void print_string(char str[])
2 {
3 // printf("%s\n", str); //原书用printf函数,编译出错
4 puts(str); //使用puts(str)可以通过编译,正确输出
5
6 return ;
7 }
~
//warning: incompatible implicit declaration of builtin function ‘printf’ [enabled by default]
[此贴子已经被作者于2016-10-13 19:30编辑过]