The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Need some help on a program. New to C!
Discuss Need some help on a program. New to C! in the C Programming forum on Dev Shed. Need some help on a program. New to C! C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 24th, 2013, 06:11 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 1
Time spent in forums: 8 m 49 sec
Reputation Power: 0
|
|
|
Need some help on a program. New to C!
Got this assignment today. Was wondering if anyone had any tips/hints on how I would go about solving this. Thanks.
You will write a small application for the Windows console, to be compiled by Tiny C, that has a function called convert() that you will fill in the code for
this function has the following prototype:
void convert (unsigned char *info, int len);
The job of this function is to take the arbitrary data that is pointed to by the parameter info (a pointer to unsigned char data), and output that information in this format:
00 01 02 03 20 30 60 A0
B0 F0 F1 F2 FA FB FC FF
10 11 22 33 40 50 70 80
90 A0 B1 C2 DA EB FA FE
A2 B4
Etc.
You will output via printf() all the data from where info points to , for len number of bytes in the above format (2 digit hex output). There will be 8 bytes output per line, and you will stop output as soon as you have completed len number of bytes.
The above output would, for example, correspond to a value of 34 for the len parameter.
Your main function will supply test data, and you can copy/paste the following into your solution to test out your convert() function:
int
main (void)
{
char *test1 = Hello how are you; // len will be set to strlen (test1)
char test2[] = { A, B, C, D, E, F }; // len will be set to sizeof (test2)
char buffer[100]; // len will be set to 100
int x;
// fill the buffer with some arbitrary data
for (x = 0; x < 100; x++) {
buffer[x] = x + 1;
}
// test #1
convert (test1, strlen (test1));
// test #2
convert (test2, sizeof (test2));
// test #3
convert (buffer, 100);
return 0;
}
|

January 24th, 2013, 10:22 PM
|
 |
Contributing User
|
|
|
|
There's a bit of trouble with the test framework. I'd fix it! It's got goofy quotation marks instead of the useful ASCII variety.
Code:
char *test1 = "Hello how are you"; // len will be set to strlen (test1)
char test2[] = {'A', 'B', 'C', 'D', 'E', 'F'};
Next I'd figure out what the expected results are. That way I'd know that my convert worked. Using executable Iverson notation I expect the results to match
Code:
TEST_DATA =: (a.i.'Hello how are you');(a.i.'ABCDEF');>:i.100
(_8&(,/\))@(,.&' ')@({&'0123456789ABCDEF')@(16 16&#:)&.>TEST_DATA
┌────────────────────────┬──────────────────┬────────────────────────┐
│48 65 6C 6C 6F 20 68 6F │41 42 43 44 45 46 │01 02 03 04 05 06 07 08 │
│77 20 61 72 65 20 79 6F │ │09 0A 0B 0C 0D 0E 0F 10 │
│75 │ │11 12 13 14 15 16 17 18 │
│ │ │19 1A 1B 1C 1D 1E 1F 20 │
│ │ │21 22 23 24 25 26 27 28 │
│ │ │29 2A 2B 2C 2D 2E 2F 30 │
│ │ │31 32 33 34 35 36 37 38 │
│ │ │39 3A 3B 3C 3D 3E 3F 40 │
│ │ │41 42 43 44 45 46 47 48 │
│ │ │49 4A 4B 4C 4D 4E 4F 50 │
│ │ │51 52 53 54 55 56 57 58 │
│ │ │59 5A 5B 5C 5D 5E 5F 60 │
│ │ │61 62 63 64 │
└────────────────────────┴──────────────────┴────────────────────────┘
Closely reading the j sentence reveals that I think 16 is an important number for your project. I might have an extra space in the right hand column. If so, prepend 0 _1&}.@ to drop no rows and the right hand column from the character arrays.
__________________
[code] Code tags[/code] are essential for python code!
Last edited by b49P23TIvg : January 24th, 2013 at 10:28 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|