字符串分行控制输出问题,请指点。
编写一个程序,要求把用户输入的字符串按照要求输出,比如:
char s[ ] = "My home is in Toronto Ontario";
int i;
i = wordWrap(s, 7);
printf("%d\n%s\n",i s);
调用函数后输出:
4
My home
is in
Toronto
Ontario
下面是小弟写的,请指点,谢谢。
#include<stdio.h>
/*wordwrap*/
main()
{
char s[100];
int i;
printf("Please enter the string you want to do wordwrap:\n");
scanf("%s", s);
i = wordWrap(s, 7);
printf("%d\n%s\n", i, s);
}
int wordWrap( char s[ ], int width )
{
int x, y;
for (x=0; x<width; x++)
{
printf("s[x]");
if (x%7==0)
printf("\n");
}
y=width/7
return y;
}
}
[ 本帖最后由 winglesswu 于 2013-4-15 10:16 编辑 ]