Home > Back-end >  C how escape character recognition
C how escape character recognition

Time:06-11

Input string, calculate the escape character/n,/a/b/t the number of such as 12 d/nb#, enter # or to stop printing, o great god answer

CodePudding user response:

It is not by the number of statistics/?

CodePudding user response:

reference 1st floor wowpH response:
that is not the number of statistics/?

But statistics letters

CodePudding user response:

refer to the original poster weixin_45846821 response:
input string, calculate the escape character/n/a,/b/t the number of such as 12 d/nb#, enter # or to stop printing, o great god answer

There is/, that how to identify?

CodePudding user response:

What don't understand,,,, how to identify one more to go,

CodePudding user response:

 
/* -
* Copyright (C), 1999-2019, mymtom.
* _
* ____ _ _ ____ _ | | _ _____ _____
* | \ | | | | (_ _) _ \ | \
* | | | | | _ | | | | | | | | | _ | | | | |
* | _ | _ _ - | | \ | _ | _ _ - | | \ () ___/| _ | _ | _ |
* (____/
*
* vi: set ts=4 sw=4:
*/

/* *
C
* @ file LetterCount.* @ brief,
*/

#include

Static int
Unescape (int ch) {
Int ret=0;
If (' a '==ch)
Ret='\ a';
Else if (' b '==ch)
Ret='\ b;
Else if (==ch 'f')
Ret='\ f;
Else if (==ch 'n')
Ret='\ n';
Else if (==ch 'r')
Ret='\ r;
Else if (' t '==ch)
Ret='\ t';
Else if (==ch 'v')
Ret='\ n';
Return ret.
}

The static char *
The escape (int ch, char * buf) {
Int ret=0;
If (\ 'a'==ch)
Ret='a';
Else if (==ch \ b)
Ret='b';
Else if (==ch \ f)
Ret='f';
Else if (=='\ n' ch)
Ret='n'.
Else if (==ch \ r)
Ret='r'.
Else if (' \ t '==ch)
Ret='t'.
Else if (==ch \ v)
Ret='v';

If (0==ret) {
Buf [0]=ch;
Buf [1]=0;
} else {
Buf [0]='\ \';
Buf [1]=ret;
Buf [2]=0;
}

Return buf.
}

Int
The main (int arg c, char * argv [])
{
int i;
Int ch;
Char buf [3].
Int count [256]={0};

While (EOF!=(ch=fgetc (stdin))) {
If (' # '==ch)
break;
If (' \ \ '==ch) {
Ch=fgetc (stdin);
If (' # '==ch)
break;
Ch=unescape (ch);
}
The count [ch] + +;
}

For (I=0; I & lt; 256; I++) {
If (count [I] & gt; 0 {
Printf (" % s: 2.2%4 d \ n ", the escape (I, buf), the count [I]);
}
}

return 0;
}

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related