- What is wrong with this code? [closed]
- #include <stdio.h>
- #include <stdlib.h>
- int main (int argc, char *argv[])
- int num;
- {
- int (num;
- float convert;
- printf("Int - float - hexn");
- int a = 0x12345678;
- unsigned char *c = (unsigned char*)(&a);
- if (*c == 0x78)
- {
- printf("nbyte order: little-endiann");
- }
- else
- {
- printf("nbyte order: big-endiann");
- }
- printf("n>");
- scanf("%d", &num);
- if (num !=0)
- {
- printf("n%10d ",num);
- printf("0x%08X",num);
- convert = (float)num; // converts
- printf("n%10.2f ", convert);
- printf("%lxn", *(unsigned long *)(&convert));
- }
- else
- {
- printf("n%10d ",num);
- printf("0x%08X",num);
- convert = (float)num; // converts
- printf("n%10.2f ", convert);
- printf("%lxn", *(unsigned long *)(&convert));
- exit(0);
- }
- return 0;
- }
- int main (int argc, char *argv[])
- int num;
- int main (int argc, char *argv[])
- int num; <----- ??? Syntax rror
- {
- printf("CS201 - A01 - Sarah Dunlap")
- int (num; <----- ??? Syntax rror
- float convert;
- int main (int argc, char *argv[])
- int num; <-- this is in the wrong place. It should go after the {
- {
- int (num; <-- you need to remove the (
- prog.c: In function ‘main’:
- prog.c:5: error: old-style parameter declarations in prototyped function definition
- prog.c:7: error: expected ‘;’ before ‘int’
- prog.c:36: error: expected declaration or statement at end of input
- int main (int argc, char *argv[])
- //Remove int num;
- {
- printf("CS201 - A01 - Sarah Dunlap"); //Add semicolon
- int num; //Remove extra parenthesis
- prog.c: In function ‘main’:
- prog.c:23: warning: dereferencing type-punned pointer will break strict-aliasing rules
- prog.c:31: warning: dereferencing type-punned pointer will break strict-aliasing rules
- prog.c:16: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
- CS201 - A01 - Sarah DunlapInt - float - hex
- byte order: little-endian
- >
- 134513664 0x08048400
- 134513664.00 4d004840