Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char* text1 = "This is a string.";
  5. char* text2 = "Yet another thing.";
  6.  
  7. int list1[20];
  8. int list2[20];
  9. int count = 0;
  10.  
  11.  
  12. void printlist(const int* lst){
  13.   printf("ASCII codes and corresponding characters.\n");
  14.   while(*lst != 0){
  15.     printf("0x%03X '%c' ", *lst, (char)*lst);
  16.     lst++;
  17.   }
  18.   printf("\n");
  19. }
  20.  
  21. void endian_proof(const char* c){
  22.   printf("\nEndian experiment: 0x%02x,0x%02x,0x%02x,0x%02x\n",
  23.          (int)*c,(int)*(c+1), (int)*(c+2), (int)*(c+3));
  24.  
  25. }
  26.  
  27. void copycodes(char* text,int* list, int* count)
  28. {
  29.  
  30.     while (*text)
  31.     {
  32.         *list = *text;
  33.         list ++;
  34.         text ++;
  35.         *count += 1;
  36.     }
  37. } // 0010 0011
  38.  
  39. void work()
  40. {
  41.     copycodes(text1, list1, &count);
  42.     copycodes(text2, list2, &count);
  43. }
  44.  
  45. int main(void){
  46.   work();
  47.  
  48.   printf("\nlist1: ");
  49.   printlist(list1);
  50.   printf("\nlist2: ");
  51.   printlist(list2);
  52.   printf("\nCount = %d\n", count);
  53.  
  54.   endian_proof((char*) &count);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement