01/10/2018, 17:32

Đếm kí tự chuỗi

Đề bài: Cho xâu S có cả chữ ha và chữ thường. Kiêmr tra xem trong xâu có đúng cả 26 chữ cái không?
Mọi người cho em hỏi là bài code em viết thế này ạ:

#include<bits/stdc++.h>
#include<string.h>
using namespace std;

int main(){
	char alphabet[]="zxcvbnmasdfghjklqwertyuiop";	
	char string[225];
	int count=0;
	gets(string);
	strlwr(string);
	for(int i=0; alphabet[i]!=''; i++){
		if(strchr(string, alphabet[i])) count++;
	}
	if(count==26) cout<<"YES";
	else cout<<"NO";
	return 0;
}

Mà em lại bị lỗi thế này là sao ạ??

Compilation Error
/tmp/code.cpp: In function ‘int main()’:
/tmp/code.cpp:9:2: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
  gets(string);
  ^
/tmp/code.cpp:9:13: warning: ‘char* gets(char*)’ is deprecated (declared at /usr/include/stdio.h:638) [-Wdeprecated-declarations]
  gets(string);
             ^
/tmp/code.cpp:10:15: error: ‘strlwr’ was not declared in this scope
  strlwr(string);
               ^
/tmp/code.cpp:9:14: warning: ignoring return value of ‘char* gets(char*)’, declared with attribute warn_unused_result [-Wunused-result]
  gets(string);

```
viết 19:39 ngày 01/10/2018

strlwr ko có trong thư viện <string.h>

C/C++ đều ko có hàm strlwr này @_@

Nguyễn Xuân Hậu viết 19:34 ngày 01/10/2018

Vậy ạ, thế mình dùng tolower được không ạ?

viết 19:38 ngày 01/10/2018

ừ, làm cái vòng for rồi gán string[i] = tolower(string[i])

rogp10 viết 19:34 ngày 01/10/2018

Bài này thì quẩy bảng tần suất cho nhẹ

Bài liên quan
0