c语言 3 急求 ~~~有追加

来源:百度知道 编辑:UC知道 时间:2024/05/21 06:48:09
输入三个字符串 并将其连接成一个字符串 查找出所有的字母e出现的位置 例如输入字符串english have bee 输出连接后的字符串是englishhavebee 字母出现的位置有:1,11,13,14

楼上错误,输入english have bee, 输出结果为-1 10 13 14
写的下面这个程序可正确输出题目的要求:
englishhavebee
1 11 13 14

#include <stdio.h>
#include <string.h>

int main()
{
char line[3][4096], search='e';
int pos=1, i=0, j=0;

for(i=0; i!=3; ++i)
{
scanf("%s", line[i]); //input strings
}

for(i=0; i!=3; ++i)
{
printf("%s",line[i]); //output combined string
}
printf("\n");

for(i=0; i!=3; ++i) //calculate position of e and output
{
for(j=0; j!=strlen(line[i]); ++j)
{
if( line[i][j]==search )
{
printf("%d ", pos);
}
pos++;
}
}

printf("\n");
return 0;
}

#include <stdio.h>
#include <string.h>

int main(){
char line[4096], search='e';
int len=0, i=0, j=0;