Exercise 3-8 (Digraphs and trigraphs in C/C++)

Chapter_3     Exercise_3-7     ReinterpretCast Exercise_3-12     Exercise_3-9







Exercise 3-8     TCP1, p. 227


Exercise 3-8. Write a program that uses all the trigraphs to see if your compiler supports them.




CONTENTS:     digraphs.c     Digraphs.cpp     trigraphs.c     Trigraphs.cpp




Note:  See Digraphs_and_trigraphs on Wikipedia.




digraphs.c         download


%:include <stdio.h> // for printf()

int main()
<%
char hello<::> = "Hello!";

printf("%s\n", hello);

return 0;
%>
/*
gcc digraphs.c -o digraphs // compiles directly
./digraphs
Hello!
*/











Digraphs.cpp         download


%:include <iostream>
using std::cout;
using std::endl;

int main()
<%
char hello<::> = "Hello!";

cout << hello << endl;

return 0;
%>
/*
g++ Digraphs.cpp -o Digraphs // compiles directly
./Digraphs
Hello!
*/











trigraphs.c         download


??=include <stdio.h> // for printf()

int main()
??<
printf("Trigraphs in C:??/n");
printf("??/???/?=??/t??=??/n");
printf("??/???/?/??/t??/??/??/n");
printf("??/???/?'??/t??'??/n");
printf("??/???/?(??/t??(??/n");
printf("??/???/?)??/t??)??/n");
printf("??/???/?!??/t??!??/n");
printf("??/???/?<??/t??<??/n");
printf("??/???/?>??/t??>??/n");
printf("??/???/?-??/t??-??/n");

return 0;
??>
/*
gcc trigraphs.c -trigraphs -o trigraphs // needs option -trigraphs to compile
./trigraphs
Trigraphs in C:
??= #
??/ \
??' ^
??( [
??) ]
??! |
??< {
??> }
??- ~
*/











Trigraphs.cpp         download


??=include <iostream>
using std::cout;
using std::endl;

int main()
??<
cout << "Trigraphs in C++:" << endl;
cout << "??/???/?=??/t??=" << endl;
cout << "??/???/?/??/t??/??/" << endl;
cout << "??/???/?'??/t??'" << endl;
cout << "??/???/?(??/t??(" << endl;
cout << "??/???/?)??/t??)" << endl;
cout << "??/???/?!??/t??!" << endl;
cout << "??/???/?<??/t??<" << endl;
cout << "??/???/?>??/t??>" << endl;
cout << "??/???/?-??/t??-" << endl;

return 0;
??>
/*
g++ Trigraphs.cpp -trigraphs -o Trigraphs // needs option -trigraphs to compile
./Trigraphs
Trigraphs in C++:
??= #
??/ \
??' ^
??( [
??) ]
??! |
??< {
??> }
??- ~
*/









Chapter_3     Exercise_3-7     ReinterpretCast BACK_TO_TOP Exercise_3-12     Exercise_3-9



Comments

Popular posts from this blog

Contents