一个程序中断问题,请大家帮帮忙!!!!
#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