Hi,
I wanted to test the serial port, i checked it on my laptop, I expected to have a pointer null or something like this.
Unfortunately I got "segmentation fault"
Is this program correct to detect serial port . I am working on linux.
#include <stdio.h>
// Just to check if serial ports are activated
int main(){
unsigned int *ptr, address;
int a,k;
ptr=(unsigned int *)0x00000400;
printf(" ptr = %X give a number (for pause )", (unsigned int)ptr);
scanf("%d",&k); for(a=0; a<4; a++){
printf(" ptr = %X *ptr=%d give number", (unsigned int) ptr, *ptr);
scanf("%d",&k);
address =*ptr; if (address == 0)
printf("The port COM%d disabled \n",a+1);
else
printf("The port COM%u is %X \n",a+1, address);
*ptr++;
}
}
/*
$ gcc port.c -o portSer
~$ ./portSer ptr = 400 give a number (for pause )1
Segmentation fault
the error is at line 11 (just after for ) , if I remove *ptr
the program continues until lines 13 ( address =*ptr, so the problem is in
*ptr the object pointed
*/