C 文件 简单整理 根据莫大学毕业项目写

#define  _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "ctype.h"
#include "stdlib.h"
int main1111(void)
{
	FILE *fpi, *fpo;
	int ch, f, lch; int dqm, sqm, par,Gh;
	fpi = fopen("ininin.txt", "r");
	fpo = fopen("tmpout.txt", "w");
	if (fpi == NULL || fpo == NULL){
		printf("Open the file(s) failure...\n");
		exit(0);
	}
	 dqm = sqm = par =Gh= 0;
	while (ch = fgetc(fpi), !feof(fpi))
	{
 test1:if (ch != ' ')
		{
			if (par == 0)
			{
				if (ch >= 'a'&&ch <= 'z')
				{
					ch = ch - 32;
					fputc(' ', fpo);
					fputc(' ', fpo);
					fputc(ch, fpo);
					f = ch;
					par = 1;
					printf("%c", ch-32);
				}
				else
				{
					if (ch >= 'A' && ch <= 'Z')
					{
						fputc(' ', fpo);
						fputc(' ', fpo);
						fputc(ch, fpo);
						f = ch;
						par = 1;
						printf("%c", ch);
					}
				}
				lch = ch;
				continue;
			}
			else if (lch==' ')
			{
				fputc(lch, fpo);
				lch = ch;
			//	f = ch;
				printf("%c", ch);
				goto test1;
			}
			if (ch >= 'A' && ch <= 'Z')
			{
				if (lch != ' '&&lch != ',' &&lch != ';' && lch != ':')
				{
					fputc(' ', fpo);
					fputc(ch, fpo);
					lch = ch;
					f = ch;
					printf("%c", ch);
					continue;
				}
				else
				{
					fputc(ch, fpo);
					lch = ch;
					f = ch;
					printf("%c", ch);
					continue;
				}
			}
			if (ch == ',' || ch == ';' || ch == ':')
			{
				fputc(ch, fpo);
				fputc(' ', fpo);
				lch = ch;
			
				printf("%c", ch);
				continue;
			}
			else if (ch == '.' || ch == '!' || ch == '?')
			{
				if (dqm)
				{
					fputc(ch, fpo);
					fputc(' ', fpo);
					lch = ch;
					f = ch;
					printf("%c", ch);
					continue;
				}
				else
				{
					fputc(ch, fpo);
					fputc(' ', fpo);
					fputc('\n', fpo);
					par = 0;
					lch = ch;
					f = ch;
					printf("%c", ch);
					continue;
				}
				
			}
			else if (ch == '\n')
			{
				if (lch == '.' || lch == '?' || lch == '!'&&dqm==0)
				{
					fputc(ch, fpo);
					f = ch;
					par = 0;
					printf("%c", ch);
				}
				
				else
				{
					fputc(' ', fpo);
					f = ch;
					printf("%c", ch);
					continue;
				}
			}
			else if (ch == '\"')
			{
				if (dqm)
				{
					if (f == '.' || f == '!' || f == '?')
					{
						lch = ch;
						ch = fgetc(fpi);
						if (ch == '\"')
						{
							fputc(lch,fpo);
							fputc(' ', fpo);
							fputc(ch, fpo);
					//		fputc('\n', fpo);
					//		dqm = 0;
							lch = ch;
							f = ch;
							continue;
						}
						else if (ch == EOF)
						{
							fputc(lch, fpo);
							fputc(' ', fpo);
							break;
						}
						else
						{
							fputc(lch, fpo);
							fputc(' ', fpo);
							fputc('\n', fpo);
							dqm = 0;
							par = 0;
							goto test1;
						}
					}
					else if (lch=='\"')
					{
						
						fputc(ch, fpo);
						dqm = 0;
						lch = ch;
						f = ch;
						continue;
					}
					else
					{
						fputc(ch, fpo);
						fputc(' ', fpo);
						dqm = 0;
						lch = ch;
						f = ch;
						continue;
					}
				
				}
				else
				{
					if (lch == ',' || lch == ';' || lch == ':')
					{
						fputc(ch, fpo);
						f = ch;
						dqm = 1;
					}
					else if (lch != ' '&&lch!='\"'&&lch != ',' && lch != ';' && lch != ':')
					{
						fputc(' ', fpo);
						fputc(ch, fpo);
						f = ch;
						dqm = 1;
					}
					else
					{
						fputc(ch, fpo);
						f = ch;
						dqm = 1;
					}
				}
			}
			else if (ch == '\'')
			{
				if (sqm)
				{
					if (lch == '.' || lch == '?' || lch == '!')
					{
						fputc(ch, fpo);
						fputc('\n', fpo);
						sqm = 0;
						par = 0;
					}
					else
					{
						fputc(ch, fpo);
						f = ch;
						fputc(' ', fpo);
						sqm = 0;
					}
					
				}
				else
				{
					if (lch == ',' || lch == ';' || lch == ':')
					{
						fputc(ch, fpo);
						f = ch;
						sqm = 1;
					}
					else if (lch != ' '&&lch != ',' || lch != ';' || lch != ':')
					{
						fputc(' ', fpo);
						fputc(ch, fpo);
						f = ch;
						sqm = 1;
					}
				}
			}
			else if (ch == '(')
			{
				if (lch == ',' || lch == ';' || lch == ':')
				{
					fputc(ch, fpo);
					f = ch;
				}
				else if (lch != ' '&&lch != ',' || lch != ';' || lch != ':')
				{
					fputc(' ', fpo);
					fputc(ch, fpo);
					f = ch;
				}
			}
			else if (ch == ')')
			{
				fputc(ch , fpo);
				fputc(' ', fpo);
				f = ch;
			}
			else 
			{
				fputc(ch, fpo);
			}
		}
		lch = ch;
	}
	fclose(fpi);
	fclose(fpo);
	return 0;
}

你可能感兴趣的:(C 文件 简单整理 根据莫大学毕业项目写)