範例在這邊:
 #include <stdio.h>
int
main()
{
    char buf[] = "1234";
    int *c = (int *) &buf;
    printf("c = '%d'\n", *c);
    printf("c = '%x'\n", ntohl(*c));
    printf("%d\n", sizeof(int));
    printf("%p\n", buf);
    printf("%p\n", &buf[0]);
    return 0;
}
1. 假設讀檔讀入的 buf 是 "1234";
2. 指定(int *) c 到 buf 的位置
3. 需要再反轉 byte order ,也需要注意 sizeof 的問題
 
 
 
沒有留言:
張貼留言