Guest User

Untitled

a guest
Jul 4th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. What is wrong with this code? [closed]
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int main (int argc, char *argv[])
  5. int num;
  6. {
  7. int (num;
  8.  
  9. float convert;
  10. printf("Int - float - hexn");
  11.  
  12. int a = 0x12345678;
  13. unsigned char *c = (unsigned char*)(&a);
  14. if (*c == 0x78)
  15. {
  16. printf("nbyte order: little-endiann");
  17. }
  18. else
  19. {
  20. printf("nbyte order: big-endiann");
  21. }
  22. printf("n>");
  23. scanf("%d", &num);
  24. if (num !=0)
  25. {
  26. printf("n%10d ",num);
  27. printf("0x%08X",num);
  28.  
  29. convert = (float)num; // converts
  30.  
  31. printf("n%10.2f ", convert);
  32. printf("%lxn", *(unsigned long *)(&convert));
  33. }
  34. else
  35. {
  36. printf("n%10d ",num);
  37. printf("0x%08X",num);
  38.  
  39. convert = (float)num; // converts
  40.  
  41. printf("n%10.2f ", convert);
  42. printf("%lxn", *(unsigned long *)(&convert));
  43. exit(0);
  44. }
  45.  
  46. return 0;
  47. }
  48.  
  49. int main (int argc, char *argv[])
  50. int num;
  51.  
  52. int main (int argc, char *argv[])
  53. int num; <----- ??? Syntax rror
  54. {
  55. printf("CS201 - A01 - Sarah Dunlap")
  56. int (num; <----- ??? Syntax rror
  57.  
  58. float convert;
  59.  
  60. int main (int argc, char *argv[])
  61. int num; <-- this is in the wrong place. It should go after the {
  62. {
  63.  
  64. int (num; <-- you need to remove the (
  65.  
  66. prog.c: In function ‘main’:
  67. prog.c:5: error: old-style parameter declarations in prototyped function definition
  68. prog.c:7: error: expected ‘;’ before ‘int’
  69. prog.c:36: error: expected declaration or statement at end of input
  70.  
  71. int main (int argc, char *argv[])
  72. //Remove int num;
  73. {
  74. printf("CS201 - A01 - Sarah Dunlap"); //Add semicolon
  75. int num; //Remove extra parenthesis
  76.  
  77. prog.c: In function ‘main’:
  78. prog.c:23: warning: dereferencing type-punned pointer will break strict-aliasing rules
  79. prog.c:31: warning: dereferencing type-punned pointer will break strict-aliasing rules
  80. prog.c:16: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
  81.  
  82. CS201 - A01 - Sarah DunlapInt - float - hex
  83.  
  84. byte order: little-endian
  85.  
  86. >
  87. 134513664 0x08048400
  88. 134513664.00 4d004840
Advertisement
Add Comment
Please, Sign In to add comment