一个程序中断问题,请大家帮帮忙!!!!

luojinzhong2002 2006-09-07 03:47:30
#include <stdio.h>
#include <string.h>
该程序的作用是:输入带空格或带逗号的数字与字母混合的字符串,以空格或逗号作为一个单词的开始和结束的标志,统计输入的字符串中单词的个数及每个单词有多少个字符!!

#define MAX_TANGO_TBL 40
typedef struct tango{
char *pword;
int len;
} TANGO;

int get_tango(char *, TANGO *);

void main(void)
{
char buffer[81];
char *pbuf;
int tango_cnt;
TANGO tango_tbl[MAX_TANGO_TBL];
TANGO *ptbl;
int i;

pbuf = buffer;
ptbl = tango_tbl;

printf( "输入:aaaaa,bbbbb,11111 aa 222\n" );
printf( "输入(Max80bytes) : " );
gets( buffer );

tango_cnt = get_tango( pbuf, ptbl );

for( i = 0; i < tango_cnt; i++ )
printf( "%d %.*s %d文字\n", i+1, *((ptbl+i)->pword) , (ptbl+i)->len );

printf( "終了" );
gets( buffer );
}

int get_tango(char *pbuf, TANGO *ptbl)
{
int flag = 0;
int cnt = 0;

while( *pbuf != NULL ) {
if( !flag ) {
if( *pbuf != ' ' || *pbuf != ',' ) {
flag = 1;
cnt++;
ptbl->pword=&(*pbuf);
ptbl->len=1;
}
}
else {
if( *pbuf == ' '||*pbuf == ',' ) {
flag = 0;
ptbl->len=1;
/* continue;*/
}
else
(ptbl->len)++;
}
pbuf++;
}
return cnt;
}
运行时程序会中断,其中这三条语句:
printf( "%d %.*s %d文字\n", i+1, *((ptbl+i)->pword) , (ptbl+i)->len );
ptbl->pword=&(*pbuf);
ptbl->len=1;
我认为有编写错误,如果有的话,如何改??谢谢!1
...全文
108 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
aminconi 2006-09-07
  • 打赏
  • 举报
回复
printf( "%d %.*s %d文字\n", i+1, *((ptbl+i)->pword) , (ptbl+i)->len );
少个参数
%.*s需要一个整型参数和一个字符串型参数
luojinzhong2002 2006-09-07
  • 打赏
  • 举报
回复
我也不太明白!!1这是到考试题
sumjohn 2006-09-07
  • 打赏
  • 举报
回复
printf( "%d %.*s %d文字\n", i+1, *((ptbl+i)->pword) , (ptbl+i)->len );
这个 %.*s 是什么意思?
luojinzhong2002 2006-09-07
  • 打赏
  • 举报
回复
注释语句忘记加/* */
/*该程序的作用是:输入带空格或带逗号的数字与字母混合的字符串,以空格或逗号作为一个单词的开始和结束的标志,统计输入的字符串中单词的个数及每个单词有多少个字符!!*/

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧