user-0 提问: 在线等，急+++++求指导

回复:
user: user-0
content: 引用 3 楼 cs290473786 的回复:没有具体测试。 #include <iostream> #include <fstream> #include <stack> using namespace std;  struct CharInfor { 	int row; 	int column; 	int type;//0表示'('，1表示')' };  int main() { 	fstream fileStream; 	fileStream.open("aa.cpp", ios::in);  	stack<CharInfor> charStack; 	char readChar; 	int nowRow = 0; 	int nowColumn = 0; 	CharInfor tempInfor; 	while (fileStream.read(&readChar, 1)) 	{ 		nowColumn++; 		tempInfor.column = nowColumn; 		tempInfor.row = nowRow; 		if (readChar == '(') 		{ 			tempInfor.type = 0; 			charStack.push(tempInfor); 		} 		if (readChar == ')') 		{ 			tempInfor.type = 1; 			if (charStack.empty()) 			{ 				break; 			} 			charStack.pop(); 		} 		if (readChar == '\n') 		{ 			nowColumn = 0; 			nowRow++; 		} 	} 	if (fileStream.eof() == true) 	{ 		if (charStack.size() > 0) 		{ 			cout << "(错误:" << charStack.top().row << "行" << charStack.top().column << "列" << endl;//只显示了一个 		} 		else 		{ 			cout << "正常" << endl; 		} 	}  	else 	{ 		cout << ")错误:" << tempInfor.row << "行" << tempInfor.column << "列" << endl;//只显示了一个 	} 	return 0; }  我表示C++不是强项。。不过谢谢帮忙了，我回头帮你测试一下

user: user-0
content: 引用 4 楼 u013163178 的回复:写的不好。 /*************************************************************************     > File Name: fgetc.c     > Author: Jukay     > Mail: iloveyouljxcc@163.com      > Created Time: 2014年10月13日 星期一 17时46分01秒  ************************************************************************/ #include<stdlib.h> #include<stdio.h> #include<string.h> int main() { 	FILE *fstream; 	char* buffer; 	// get char 	int ch; 	buffer = (char*)malloc(32); 	fstream = fopen("aa.txt","r"); 	if(fstream == NULL) 	{ 		fprintf(stderr,"%s\n","failed to open aa.txt\n"); 		exit(0); 	} 	//the position of the char in  average line 	int nch = 0; 	//number of line 	int nln = 0; 	char *pos = buffer; 	//the position of ')' 	int n; 	while((ch=fgetc(fstream)) !=EOF) 	{ 		nch++; 		if(ch =='(' ) 		{ 			buffer++; 			*buffer = ch; 		}		 		if(ch ==')') 		{ 			if(*buffer =='(') 			{ 				*buffer ='\0'; 				buffer--; 			} 			else 				//error here 				n = nch; 		} 		if(ch =='\n') 		{ 			nln++; 			if(pos == buffer) 				printf("the %dth line is ok!\n",nln); 			else 				printf("the %dth line %dth char is error\n",nln,n); 			// clear the position of "(" 			n = 0; 			nch = 0; 			buffer =pos; 			memset(buffer,'\0',32); 		} 	} }  谢谢了哈。。。写的比我的好多了

user: user-1
content: 写的不好。 /*************************************************************************     > File Name: fgetc.c     > Author: Jukay     > Mail: iloveyouljxcc@163.com      > Created Time: 2014年10月13日 星期一 17时46分01秒  ************************************************************************/ #include<stdlib.h> #include<stdio.h> #include<string.h> int main() { 	FILE *fstream; 	char* buffer; 	// get char 	int ch; 	buffer = (char*)malloc(32); 	fstream = fopen("aa.txt","r"); 	if(fstream == NULL) 	{ 		fprintf(stderr,"%s\n","failed to open aa.txt\n"); 		exit(0); 	} 	//the position of the char in  average line 	int nch = 0; 	//number of line 	int nln = 0; 	char *pos = buffer; 	//the position of ')' 	int n; 	while((ch=fgetc(fstream)) !=EOF) 	{ 		nch++; 		if(ch =='(' ) 		{ 			buffer++; 			*buffer = ch; 		}		 		if(ch ==')') 		{ 			if(*buffer =='(') 			{ 				*buffer ='\0'; 				buffer--; 			} 			else 				//error here 				n = nch; 		} 		if(ch =='\n') 		{ 			nln++; 			if(pos == buffer) 				printf("the %dth line is ok!\n",nln); 			else 				printf("the %dth line %dth char is error\n",nln,n); 			// clear the position of "(" 			n = 0; 			nch = 0; 			buffer =pos; 			memset(buffer,'\0',32); 		} 	} }

user: user-2
content: 没有具体测试。 #include <iostream> #include <fstream> #include <stack> using namespace std;  struct CharInfor { 	int row; 	int column; 	int type;//0表示'('，1表示')' };  int main() { 	fstream fileStream; 	fileStream.open("aa.cpp", ios::in);  	stack<CharInfor> charStack; 	char readChar; 	int nowRow = 0; 	int nowColumn = 0; 	CharInfor tempInfor; 	while (fileStream.read(&readChar, 1)) 	{ 		nowColumn++; 		tempInfor.column = nowColumn; 		tempInfor.row = nowRow; 		if (readChar == '(') 		{ 			tempInfor.type = 0; 			charStack.push(tempInfor); 		} 		if (readChar == ')') 		{ 			tempInfor.type = 1; 			if (charStack.empty()) 			{ 				break; 			} 			charStack.pop(); 		} 		if (readChar == '\n') 		{ 			nowColumn = 0; 			nowRow++; 		} 	} 	if (fileStream.eof() == true) 	{ 		if (charStack.size() > 0) 		{ 			cout << "(错误:" << charStack.top().row << "行" << charStack.top().column << "列" << endl;//只显示了一个 		} 		else 		{ 			cout << "正常" << endl; 		} 	}  	else 	{ 		cout << ")错误:" << tempInfor.row << "行" << tempInfor.column << "列" << endl;//只显示了一个 	} 	return 0; }

user: user-3
content: 挨个读取字符 碰到左括号入栈 碰到右括号出栈 最后判断栈是否为空

user: user-0
content: 求帮助啊！！！！