Добрый день уважаемые программисты. Подскажите пожалуйста почему программа выдает ошибку.
Вот код:
| Код | #include <math.h> #include <string.h> #include <iostream.h> #define l 2
int main () { int b,i=0,j,temp=0,n=0; char* mas_words[100]; char* buf=""; int mas_num[100]; int mas_words_repeat[100]={0}; char str[100] ="My name is vova"; cout << "Enter the string:"; /*cin >> str;*/ char * pch; cout << "Start string: \n\n" << str <<"\n\n"; pch = strtok (str," ,.-()"); while (pch != NULL) { mas_words[i]=pch; mas_num[i]=strlen(pch); pch = strtok (NULL, " ,.-()"); i++; n++; } for(j=0;j<n;j++){ for(i=0;i<n;i++){ if(mas_num[i+1]>mas_num[i]){ temp=mas_num[i]; mas_num[i]=mas_num[i+1]; mas_num[i+1]=temp; buf=mas_words[i]; mas_words[i]=mas_words[i+1]; mas_words[i+1]=buf; } } } for(i=1;i<n;i++){ for(j=1;j<n;j++){ if(strcmp(mas_words[i],mas_words[j])==0){ mas_words_repeat[i]+=1; } } } for(i=1;i<n;i++){ for(j=1;j<n;j++){ if(strcmp(mas_words[i],mas_words[j])==0 && i!=j){ mas_words[i]="0"; } } } cout << "Words: Counts: Repeats:\n"; for(i=1;i<=l;i++){ if(strcmp(mas_words[i],"0")!=0){ cout << mas_words[i] << " "; cout << mas_num[i] << " "; cout << mas_words_repeat[i] << ""; cout << "\n"; } } scanf("%d",&b); }
|
Если так то все работает, но если заменить:
| Код | char str[100] =""; cout << "Enter the string:"; cin >> str;
|
выдает ошибки.
Задача состоит в том чтобы переменную str не описывать а вводить с клавиатуры.
|