0
如何標點符號correcter工作:: 如果我有這樣一行:標點符號修正?
hi.how are u?i'm good;ok bye.
的correcter應該給我這一行:
hi. How are u? I'm good; ok bye.
如何工作: 第一之後的任何{。或者,或;要麼 ? }它應該把一個空格和大寫之後的字母?
用C
UPDATE
#include<stdio.h>
#include<string.h>
#define LINE_LEN 300
void strip(char *);
char toCap(char);
char toSml(char);
int main(int argc, char *argv[]){
char line[LINE_LEN];
int counter = 0;
int line_length;
int i;
char outline[LINE_LEN];
if(argv[1] == NULL){ //check if the file exists or not
printf("ERROR: FILE NOT FOUND!\n");
return -1;
}
FILE *inp;
FILE *output;
inp = fopen(argv[1],"r");
output = fopen("Clear_Data.txt","w");
while(fgets(line,LINE_LEN,inp) != NULL){
strip(line);
line_length = strlen(line);
for(i = 0; i < line_length ; i++)
line[i] = toSml(line[i]);
for(i = 0; i < line_length ; i++){
if(line[i] == '.' || line[i] == ',' || line[i] == ';' || line[i] == '?'){
if(line[i+1] == ' ')
outline[i+2] = toCap(line[i+2]);
else{
outline[i+1] = ' ';
outline[i+2] = toCap(line[i+1]);
}
continue;
}
else
outline[i] = line[i];
}
fprintf(output,"%s",outline);
}
fclose(inp);
fclose(output);
return 0;
}
void strip(char *str){ //remove extra whitespaces in a string
int r = 0; //next character to be read
int w = 0; // next character to be written
while(str[r]){
if (str[r] == ' ' || iscntrl(str[r])){
if (w > 0 && str[w-1] != ' ')
str[w++] = ' ';
}
else
str[w++] = str[r];
r++;
}
str[w] = 0;
if(str[strlen(str) - 1] == ' ')
str[strlen(str) - 1] = 0;
printf("%s\n",str);
}
char toCap(char c){
return (c - 32);
}
char toSml(char c){
return (c + 32);
}
但是這是行不通的任何幫助,現在?
當你的問題被關閉時,你應該改進它,而不是僅僅發佈一次。 – ypnos 2010-12-08 09:43:22
我加了什麼,我的問題,不只是張貼一遍,你需要更多我會把它,?? – 2010-12-08 09:44:40