Sample code of how to use the library
Sample code of how to use the library
Blueprint information
- Status:
- Not started
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Approved
- Assignee:
- None
- Definition:
- Approved
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by
Related branches
Related bugs
Sprints
Whiteboard
Put the following in a "Encoder.c" and compile to "Encoder.exe" (and link to the library)
#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h> /* xdr is a sub-library of rpc */
#pragma comment(lib, "Ws2_32.lib") // Library for ntohl and htonl
main()
{
XDR xdrs;
long i;
FILE* fp;
fp = fopen( "C:\\Output\
xdrstdio_
for (i = 0; i < 100; i++) {
if (!xdr_long(&xdrs, &i)) {
}
}
exit(0);
}
Put the following in a "Decoder.c" and compile to "Decoder.exe" (and link to the library)
#include <stdio.h>
#include <stdlib.h>
#include <rpc/rpc.h> /* xdr is a sub-library of rpc */
#pragma comment(lib, "Ws2_32.lib") // Library for ntohl and htonl
main()
{
// Reopens stdin to be the same input stream but in binary mode
XDR xdrs;
long i, j;
FILE* fp;
fp = fopen( "C:\\Output\
xdrstdio_
for (j = 0; j < 100; j++)
{
if (!xdr_long(&xdrs, &i)) {
}
printf("%ld ", i);
}
printf("\n");
exit(0);
}
Run Encoder.exe | Decoder.exe when both are built.
If Encoder.exe is successful, the numbers 0-100 should be in "file.txt". If Decoder.exe is successful, the numbers 0-100 should be printed.
Note that the we are opening the file in binary mode as is required.
You can also use stdin and stdout instead of an actual file. Remember to change the streams to binary (can be done with freopen()).