C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 24th, 2013, 06:11 PM
cauterize cauterize is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 cauterize User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}

Reply With Quote
  #2  
Old January 24th, 2013, 10:22 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 33 m 51 sec
Reputation Power: 383
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Need some help on a program. New to C!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap