Exercise 3-2

xiaoxiao2021-03-06  40

/ *

Write a function ESCAPE (S, T), copy the string T into the string S, and will never in the replication process,

The invisible characters such as tabs are converted to / n, / t, respectively, correspondingly visible escape character sequences. Requirements

Switch statement. Reparse a function with the opposite function, convert the escape character sequence to

Actual characters.

* /

Char * escape (char * s, char * t)

{

Char * TEMP = S;

IF (NULL == T || null == s) Return null;

For (; * t! = '/ 0'; t ) {

Switch (* t) {

Case '/ n':

* (TEMP ) = '//'; * (TEMP ) = 'n';

Break;

Case '/ t':

* (TEMP ) = '//'; * (TEMP ) = 't';

Break;

DEFAULT:

* (TEMP ) = * T;

Break;

}

} // end for

* temp = '/ 0';

Return S;

}

Char * unescape (char * s, char * t)

{

Char * TEMP = S;

IF (NULL == T || null == s) Return null;

For (; * t! = '/ 0'; t ) {

IF ('//' == * t && (* (t 1) == 'T' || * (T 1) == 'n')) {

Switch (* (t 1)) {

Case 'T':

* (TEMP ) = '/ t'; t ;

Break;

Case 'n':

* (TEMP ) = '/ n'; t ;

Break;

DEFAULT:

Break;

} // End Switch

}

ELSE * (TEMP ) = * T;

} // end for

* temp = '/ 0';

Return S;

}

//

转载请注明原文地址:https://www.9cbs.com/read-116975.html

New Post(0)