首页 > 代码库 > WC项目
WC项目
#include<iostream> #include<fstream> #include<string> #include<Windows.h> using namespace std; void main() { char word[150][15]; int AllChar = 0, NoteSize = 0, Row = 1, WordSize = 0; char a[15], c, file[15]; int i = 0, j = 0; FILE *fp; cout << "#结束输入" << endl; cin >> file; while (1) { if (file[0] == ‘#‘) break; fp = fopen(file, "r"); if (fp == NULL) { cout << "the file:y.txt not found!" << endl; exit(-1); } c = fgetc(fp); AllChar++; if (c == ‘/‘) { c = fgetc(fp); AllChar++; if (c == ‘/‘) NoteSize++; } c = fgetc(fp); AllChar++; while (c != EOF) { if ((c >= ‘a‘&&c <= ‘z‘) || (c >= ‘A‘) && (c <= ‘Z‘)) { a[i] = c; c = fgetc(fp); AllChar++; i++; continue; } else if (c == ‘/‘) { c = fgetc(fp); AllChar++; if (c == ‘/‘) { c = fgetc(fp); AllChar++; NoteSize++; continue; } } else { if (c == ‘\n‘) { Row++; } if (i != 0) { a[i] = ‘\0‘; strcpy_s(word[j], a); j++; i = 0; } c = fgetc(fp); AllChar++; } } if (i != 0) { a[i] = ‘\0‘; strcpy_s(word[j], a); j++; } fclose(fp); WordSize = j; cout << "行数:" << Row << endl; cout << "字符数:" << AllChar << endl; cout << "单词数:" << WordSize << endl; cout << "注释行:" << NoteSize << endl; cin >> file; } }
WC项目
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。