Rewriting a C++ in C

I know this forum is for C++, but I'm supposed to write my program in both C++ and C, and was hoping somebody could help me with the C part. I've converted most of my terms into C terms, and I've gotten my file to compile, but when I get to a point of calculation, I'm getting an error that says "Segmentation fault (core dumped)." Anyone have any idea whats going on? This is the section it dumps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
    printf("\nThe int min is: " -(((int) pow(2, sizeof(int)*8-1)-1)+1));

    printf("\nThe int max is: " ,(((int) pow(2, sizeof(int)*8-1)-1)+1));

    printf("\nThe unsigned int max is: " ,(((unsigned int) pow(2, sizeof(int)*8-1)-1)*2+1));


	//The computation of the largest and smallest long, signed and unsigned.
		
	printf("\nThe long min is: " -(((long) pow(2, sizeof(long)*8-1)-1)+1));

	printf("\nThe long max is: " ,(((long) pow(2, sizeof(long)*8-1)-1)+1));

	printf("\nThe unsigned long max is:  " ,(((unsigned long) pow(2, sizeof(long)*8-1)-1)*2+1));

	//The computation of the largest and smallest short, signed and unsigned.

	printf("\nThe short min is: " -(((short) pow(2, sizeof(short)*8-1)-1)+1));

	printf("\nThe short max is: " ,(((short) pow(2, sizeof(short)*8-1)-1)+1));

	printf("\nThe unsigned short max is: " ,(((unsigned short) pow(2, sizeof(short)*8-1)-1)*2+1));


Maybe I'm using a C++ only function and not realizing it?

Any help is appreciated. Thank you.
Last edited on
Segmentation faults happen when you try to access invalid memory locations

That being said, printf() requires that for every value you want to print a corresponding %t is placed in the string (t is the type, %d for int, %f for float, etc).
printf("\nThe int min is: %d", (((int) pow(2, sizeof(int)*8-1)-1)+1));

You also forgot the comma in the first funtions of each block
Last edited on
Okay that helps a lot. I'm just a little confused as to how it works. I've gotten all of them to work except for the long min. If I use %d it gives me 1 and if I use %lu it gives me 9223372036854775809
Last edited on
Did you try "%lld" or "%ld"?
Last edited on
Okay I messed around with it and found that %ld works. Thanks for the help!
Topic archived. No new replies allowed.