编程题:为了展示文件包含功能,输入一个字符串,输出其长度。

1.c源代码如下:

#include<stdio.h>

#include"2.c"

void main()           

{ char string[20];

  scanf("%s",string);         /*整个程序的功能:输入一个字符串,输出其长度*/

  printf("There are %d characters.\n",string_len(string));

}

2.c源代码如下:

int string_len(char str[])    /*求字符串长度函数*/

{ int i;

  for(i=0;str[i]!='\0';i++);  

  return i;

}

运行结果:

编程题:为了展示文件包含功能,输入一个字符串,输出其长度。 - 文豪 - WELCOME MY BLOG.