01/10/2018, 09:18
Tại sao hàm while nó ko hoạt động ạ
#include <iostream>
#define MAX_LEN 1
using namespace std;
int IsWhiteSpace(char ch)
{
return (ch == EOF);
}
void readline(char * line, int max_len, FILE *fp)
{
int dong;
cout<<"Nhap so ky tu trong 1 dong:"<<"
";
cin>>dong;
int idem=1,iline=0;
char c;
int i = 0;
while( !IsWhiteSpace(c = fgetc(fp))) {
line[i++] = c;
iline++;
if(c=='
') {
idem++;
iline=1;
}
if(iline>dong+1) {
cout<<"Dong thu"<<idem<<"da thua ki tu"<<"
";
}
}
cout<<idem;
cout<<i;
}
int main()
{
FILE * fp = fopen("input","r");
char line[MAX_LEN];
readline(line, MAX_LEN, fp);
system("pause");
}
Bài liên quan
while nó check điều kiện trước rồi mới vào thân hàm, hình như thế
thử đổi thành while(true) xem rồi khi gặp điều kiện thì break