小编azi*_*zoh的帖子

C:分段故障(核心转储)

我正在为C中的类赋值编写这个程序.它模拟读取和写入自定义大小的直接映射缓存,涉及自定义大小的主内存.

这些是我在获得之前使用的参数Segmentation fault:

Enter main memory size (words):  65536
Enter cache size (words):  1024
Enter block size (words/block):  16
Run Code Online (Sandbox Code Playgroud)

这是我的代码.它尚未完整.

#include<stdio.h>
#include<stdlib.h>

struct cache{
     int tag;
     int *block;
};

struct main {
     int value;
     int address;
     int word;

     struct main *next;
};

struct cache   *cacheptr;
struct main    *mainHd;

int main() {
    int option = 0;

    while (option != 4) {
        printf("Main memory to Cache memory mapping:\n--------------------------------------");
        printf("\n1) Set parameters\n2) Read cache\n3) Write to cache\n4) Exit\n\nEnter Selection: ");
        scanf("%d",&option); …
Run Code Online (Sandbox Code Playgroud)

c segmentation-fault

0
推荐指数
1
解决办法
124
查看次数

错误:间接需要指针操作数('int'无效)

这段代码的目的是传递一个十进制的虚拟地址并输出页码和偏移量。

在 Linux 上使用 gcc 编译器编译我的代码后,我收到此错误:

间接需要指针操作数('int'无效) virtualAddress = *atoi(argv[1]);

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <curses.h>

int main(int argc,char *argv[])

{

     unsigned long int virtualAddress,pageNumber,offset;

     if(argc<2){

          printf(" NO ARGUMNET IS PASSED");

          return 0;

     }

    virtualAddress = *atoi(argv[1]);

     //PRINT THE VIRTUAL ADDRESS

    printf("The Address %lu contains:",virtualAddress);

    //CALCULATE THE PAGENUMBER

    pageNumber = virtualAddress/4096;

     //PRINT THE PAGE NUMBER

    printf("\n Page Number = %lu",pageNumber);

    //FIND THE OFFSET

    offset = virtualAddress%4096;

    //PRINTS THE OFFSET

    printf("\n Offset = %lu",offset);

     getch(); …
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
2
解决办法
3万
查看次数

标签 统计

c ×2

segmentation-fault ×1