⑴ 在c語言環境下檢索漢字文本程序
#include<iostream>
#include<numeric>
#include<fstream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<sstream>
#include<iterator>
#include<map>
#include<windows.h>
using namespace std;
void display();
void password(int nu);
void jiequ();
void shuoming();
void main()
{
system("color 0e");
cout<<endl;
cout<<"小說文塊截取器"<<endl;
cout<<endl;
cout<<"程序自我檢測啟動!"<<endl;
cout<<endl;
cout<<"Checking.........."<<endl;
cout<<endl;
Sleep(3000);
cout<<"已確認無資料丟失,允許安全保護模塊介入........"<<endl;
Sleep(1000);
password(1);
}
void password(int nu)
{
system("cls");
cout<<endl;
if(4-nu==0)
{
cout<<endl;
cout<<"三次輸入錯誤,強制退出!!!"<<endl;
cout<<endl;
system("pause");
}else{
cout<<"請輸入程序啟動密碼(1q2w3e):"<<endl;
string PASSWORD;
cin>>PASSWORD;
if(PASSWORD=="1q2w3e")
{
display();
}else{
++nu;
cout<<endl;
cout<<"密碼錯誤!請重新輸入!!你還剩下"<<4-nu<<"次機會"<<endl;
cout<<endl;
system("pause");
password(nu);
}
}
}
void display()
{
system("cls");
cout<<endl;
cout<<"----小說文塊截取器 (MP4專用)----"<<endl;
cout<<endl;
cout<<"--------------------------------"<<endl;
cout<<endl<<endl;
cout<<" 1.開始截取"<<endl<<endl;
cout<<" 2.程序說明"<<endl<<endl;
cout<<" 3.退出程序"<<endl<<endl;
cout<<endl;
cout<<"---------------------------------"<<endl;
cout<<"請選擇:"<<flush;
string xuan;
cin>>xuan;
if(xuan!="1"&&xuan!="2"&&xuan!="3")
{
cout<<endl;
cout<<"不存在此選項!"<<endl;
system("pause");
display();
}else{
if(xuan=="1")
{
jiequ();
}
if(xuan=="2")
{
shuoming();
}
if(xuan=="3")
{
//退出模塊
}
}
}
void jiequ()
{
system("cls");
cout<<endl;
cout<<" 初用者必讀"<<endl;
cout<<endl;
cout<<"請先在小說(文章)里要開始截的地方做一個標志,再到結束截的地方做一個標志"<<endl;
cout<<endl;
cout<<"例如在小說開頭輸入一個AB,再到100章那裡開頭輸入BC,並將其保存,"<<endl;
cout<<endl;
cout<<"直接在標題那行添加!避免標志被忽略!"<<endl;
cout<<endl;
cout<<"程序將在全文中尋找這兩個標志,並將其括起並進行截取,"<<endl;
cout<<endl;
cout<<"程序不會對原文件進行任何修改,但為安全起見,還請先備份!"<<endl;
cout<<endl;
cout<<"本程序不接受任何中文輸入,請自行把文件名改為英文!"<<endl;
cout<<endl;
cout<<"本程序默認路徑為程序所在目錄路徑,使用者可把文件放在與本程序同一目錄,"<<endl;
cout<<endl;
cout<<"這樣輸入路徑處直接輸入文件名即可(切記要連後綴一起輸入)!"<<endl;
cout<<endl;
system("pause");
system("cls");
cout<<endl;
cout<<"截取模塊進入成功!"<<endl;
cout<<endl;
cout<<"請輸入開始標志:"<<endl;
string beg;
cin>>beg;
cout<<"請輸入結束標志:"<<endl;
string end;
cin>>end;
cout<<"請輸入要截取的源文件路徑(默認為當前程序目錄):"<<endl;
string way;
cin>>way;
cout<<"請輸入截取後的文件輸出路徑(默認為當前程序目錄):"<<endl;
string way_go_zhu;
cin>>way_go_zhu;
system("cls");
cout<<endl;
cout<<"開始標志為"<<beg<<endl;
cout<<"結束標志為"<<end<<endl;
cout<<endl;
cout<<endl;
cout<<"正在讀入資料..............."<<endl;
ifstream way_open(way.c_str());
if(!way_open)
{
cout<<endl;
cout<<"找不到文件!路徑錯誤!!!"<<endl;
cout<<endl;
cout<<"返回菜單............."<<endl;
cout<<endl;
system("pause");
system("cls");
display();
}else{
vector<string> word_save;
string word;
while(way_open>>word)
{
word_save.push_back(word);
}
cout<<"讀入完成."<<endl;
int kai=0,jieshu=0;
int kai_save=0,jieshu_save=0;
cout<<"正在進行截取.............."<<endl;
int OK=0;
for(vector<string>::iterator l=word_save.begin();l!=word_save.end();++l)
{
if(beg==(*l))
{
cout<<"已找到開始標志!"<<endl;
kai_save=kai;
++OK;
}
if(end==(*l))
{
cout<<"已找到結束標志!"<<endl;
jieshu_save=jieshu;
++OK;
}
++kai;
++jieshu;
}
if(OK!=2)
{
cout<<endl;
cout<<"無法找到開始(結束)標志,請檢查標志是否獨立存在,標志前後只能是空格!~"<<endl;
cout<<endl;
cout<<"請直接在題目或文章中添加標志保存即可!"<<endl;
cout<<endl;
cout<<"截取出現錯誤~~~~! 返回菜單............"<<endl;
cout<<endl;
system("pause");
display();
}else{
cout<<"截取完畢."<<endl;
cout<<endl;
ofstream zz(way_go_zhu.c_str());
cout<<endl;
cout<<"正在對文件進行資料注入............."<<endl;
int biao=0;
for(vector<string>::iterator a=word_save.begin();a!=word_save.end();++a)
{
if(biao>=kai_save&&biao<=jieshu_save)
{
zz<<*a<<endl;
}
++biao;
}
cout<<"資料注入完畢."<<endl;
cout<<"開始關閉數據流........"<<endl;
way_open.close();
way_open.clear();
zz.close();
zz.clear();
cout<<"數據流關閉完成."<<endl;
cout<<endl;
cout<<"返回菜單............"<<endl;
cout<<endl;
system("pause");
display();
}
}
}
void shuoming()
{
system("cls");
cout<<endl;
cout<<"本程序由蝦味千層糕獨立製作完成!"<<endl<<endl;
cout<<"蝦味千層糕QQ: 435952144"<<endl;
cout<<" 381426068"<<endl;
cout<<endl;
system("pause");
display();
}
⑵ C語言編程如何查找字元串中指定漢字
用數組比較方便,已兔字元為基準,前移兩個找到個數,後移三個找到顏色
⑶ C語言判斷漢字
#include<stdio.h>
intmain()
{inti;
unsignedchars[200];
scanf("%s",s);
for(i=0;s[i];i++)
if(s[i]>127)
{printf("漢字");
i++;
}
elseprintf("字母");
return0;
}
(3)c語言漢字查找擴展閱讀
C++利用漢字的ASCII編碼小於0的特性判斷漢字
//coding:utf-8
#include"stdio.h"
intmain()
{
constchar*str="ENG漢字測試ddd";
for(inti=0;str[i]!='