以下のプログラムは、目的の出力 (連続する 3 行のワード数をカウント) を提供しますが、「実行時チェックの失敗 #2 - 変数 'str' の周りのスタックが破損しています」というメッセージが表示され、ハングします。試してみましたが、解決策が見つかりませんでした。ありがとう
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int i,count=0;
int main(void){
char str[3][1000];
char *ptr;
//Get user input
puts("Enter three lines:");
for (i = 0; i < 3; i++)
{
gets(&str[i][1000]);
}
for (i = 0; i < 3; i++)
{
ptr=strtok(&str[i][1000]," ");
count++;
while (ptr!=NULL)
{
ptr=strtok(NULL, " ");
if (ptr!=NULL)
{
count++;
}
}
}
printf("%d words", count);
getch();
}