- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在尝试编写一个程序,编译器既不向我显示警告也不向我显示错误,只向我显示运行已完成的段错误核心转储,我想这与将值分配给指针,但我没有找到错误,你能帮我吗?
结构人
#ifndef PERSONSTRUCT_H
#define PERSONSTRUCT_H
#define TRUE 1
#define FALSE 0
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int edad;
char nombre[100];
}persona;
persona *getNodoPerson();
void setEdad(int, persona *);
void setNombre(char *, persona *);
#ifdef __cplusplus
}
#endif
#endif
结构节点
#define TRUE 1
#define FALSE 0
#ifndef LISTASIMPLEMENLAZADA_H
#define LISTASIMPLEMENLAZADA_H
#include "PersonStruct.h"
#ifdef __cplusplus
extern "C" {
#endif
struct nodo{
struct nodo *siguiente;
persona *person;
};
typedef struct nodo *ptrNodo;
typedef struct nodo *lista;
void freeNode(ptrNodo);
ptrNodo getNodo();
int empty(lista);
ptrNodo buscar(char[],int, lista);
int contar(lista);
void addAtEnd(char *, int, lista);
void del(lista,char *,int);
void imprimirDatos(lista);
int getPos(lista, persona *);
lista getLista();
#ifdef __cplusplus
}
#endif
#endif
结构体 nodo 的函数
#include "ListaSimplemEnlazada.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//Esta funcion elimina de memoria el nodo enviado
void freeNode(ptrNodo p)
{
free(p);
}
//Esta funcion crea el espacio de memoria para un nodo
ptrNodo getNodo()
{
ptrNodo p;
p=(ptrNodo)malloc(sizeof(struct nodo));
return p;
}
lista getLista()
{
lista l;
l=(lista)malloc(sizeof(struct nodo));
l->person=NULL;
return l;
}
//Esta funcion revisa si una lista esta vacia;
int empty(lista l)
{
int x;
if(l->siguiente==NULL)
{
x=TRUE;
}
else
{
x=FALSE;
}
return x;
}
//Esta funcion cuenta el numero de elementos que tiene una lista enlazada
int contar(lista l)
{
int cont=0;
ptrNodo aux=getNodo();
aux=l->siguiente;
while(aux!=NULL)
{
aux=aux->siguiente;
cont++;
}
return cont;
}
//Esta funcion busca en la lista especificada, el nodo en el que se encuentra la estructura se encuentra especificada
//si la estructura es encontrada, devuelve un puntero al nodo donde esta la estructura
//si no devuelve un puntero nulo
ptrNodo buscar(char *nom,int age, lista l)
{
ptrNodo aux=getNodo(),retorno=getNodo();
retorno=NULL;
if(!empty(l))
{
aux=l->siguiente;
while(aux!=NULL)
{
if ((aux->person->edad==age) && (strcmp(aux->person->nombre,nom)==0))
{
retorno=aux;
break;
}
aux=aux->siguiente;
}
}
return retorno;
}
//Ingresa un nodo al final de la lista, si la lista es vacia, lo ingresa como el primer elemento de la lista
void addAtEnd(char *nombre,int age,lista l)
{
ptrNodo aux1=getNodo(),aux2=getNodo();
aux2->person->edad=age;
strcpy(aux2->person->nombre,nombre);
aux2->siguiente=NULL;
if(!empty(l))
{
aux1=buscar(nombre,age,l);
if(aux1==NULL)
{
aux1=l->siguiente;
while(aux1!=NULL)
{
aux1=aux1->siguiente;
}
aux1->siguiente=aux2;
}
else
{
printf("El valor ya se encuentra en la lista");
}
}
else
{
l->siguiente=aux2;
}
}
//Envia la posicion numerica del nodo en la lista, retornara 0 si no encuentra el nodo
int getPos(lista l, persona *p)
{
ptrNodo aux=getNodo();
int x=0;
if(!empty(l))
{
aux=buscar(p->nombre,p->edad,l);
if(aux!=NULL)
{
aux=l->siguiente;
while(aux->person->edad==p->edad && (strcmp(aux->person->nombre,p->nombre)==0))
{
x++;
aux=aux->siguiente;
}
}
}
return x;
}
//Este metodo elimina el valor de lista
void del(lista l,char *nom,int age)
{
ptrNodo aux1=getNodo(),aux2=getNodo();
int x,i;
if(!empty(l))
{
aux1=buscar(nom,age,l);
if(aux1!=NULL)
{
x=getPos(l,aux1->person);
aux2=l->siguiente;
for(i=1;i<=(x-1);i++)
{
aux2=aux2->siguiente;
}
aux2->siguiente=aux1->siguiente;
printf("\nLa persona %s y edad %d",aux1->person->nombre,aux1->person->edad);
freeNode(aux1);
}
}
}
void imprimirDatos(lista l)
{
ptrNodo aux=getNodo();
int i=1;
if(!empty(l))
{
aux=l->siguiente;
while(aux!=NULL)
{
printf("\nLa persona numero %d con \tNombre:%s y edad:%d",i,aux->person->nombre,aux->person->edad);
i++;
}
}
}
主要内容
#include <stdio.h>
#include <stdlib.h>
#include "ListaSimplemEnlazada.h"
#include "PersonStruct.h"
/*
*
*/
int main(int argc, char** argv) {
argc=argc;
argv=argv;
char *nombres[5]={"Alberto", "Manuel","Enrique","Josue","Ronald"};
int edad[5]={25,39,45,12,21};
int i;
lista l=getLista();
for (i=0;i<=4;i++)
{
addAtEnd(nombres[i],edad[i],l);
}
imprimirDatos(l);
del(l,nombres[0],edad[0]);
imprimirDatos(l
);
return (EXIT_SUCCESS);
}
抱歉,代码量很大,但也许您需要它来理解我的程序做错了什么
最佳答案
目前,您的函数 getNodo
只是 malloc
的前端。它返回一个新的但未初始化的节点,其成员可能包含垃圾。当您在 attAtEnd
中取消引用 aux2->person
时:
aux2->person->edad=age;
你会遇到段错误。您不仅必须分配,还必须填充节点,即用合理的数据填充它。 (该数据也可能意味着 aux2->person == NULL,但如果这是有效的,您应该在取消引用指针之前检查它。)
除了西类牙语和英语的奇怪混合之外,您的函数命名也不好:get
表明您正在尝试访问现有内存。您的函数可能应该命名为 newNode
或 crearNodo
。
关于c - 程序不运行(RUN FINISHED 分段故障核心转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27104182/
我已经通过 AVD 管理器启动了我的模拟器,一旦它运行,我点击了 run app。我已经等了几分钟,我的正在运行的设备出现在 选择一个正在运行的设备 中,但窗口始终保持空白。 最佳答案 您正在运行的项
我想在安装新数据库之前删除旧数据库,以便为用户更新它。 我有以下情况: 在我的 Components 部分中,我为用户提供了一个选项: [Components] Name: "updateDataba
如果我将一个 Python 模块实现为一个目录(即包),它同时具有顶级函数 run 和子模块 run,我可以指望 from example import run 总是导入函数?根据我的测试,至少在 L
我在 Eclipse Juno 上使用 Tomcat 7。我使用工作区元数据作为服务器位置(请参阅下面的我的 tomcat 配置)。 我也收到了 服务器项目在 eclipse [请看下图] 中使用单独
我正在做一些测试以了解 java 中的不同线程状态,并且遇到了一些查询。 通常,当一个线程被实例化时,它被称为处于 "NEW" 状态,然后当调用它的 start() 方法时,操作系统调度程序获得控制权
当我使用命令 npm run build -- --prod 时,我收到以下错误消息: 属性“PropertyName1”是私有(private)属性,只能在“AppComponent”类中访问 “A
我正在尝试将默认的“运行”键盘快捷键更改为 ⌘R。 - 因为我不想每次都伸手去拿触控板,而且我的手指不够长,无法一次执行⌥⇧F10。 “运行”和“运行...”有什么区别? 最佳答案 ... 用于菜单中
我现在不知道如何编写一个合适的方法来测试这种行为。请不要投反对票.. 我现在有一个 java 类负责处理数据并将数据添加到多个数据库。每个数据库都保存相同的数据,但处理方式不同(例如,以不同的插值率进
我知道不应该调用 run 方法来启动新线程执行,但我指的是 this article他们在另一个 run 方法中调用了 runnable.run(); ,这似乎暗示它启动了一个新线程或者根本没有cre
当我尝试在Windows 10/11下使用Eclipse 2023-06调试任何应用程序(甚至是hello.c)时,我总是收到以下错误:。该错误清楚地指示-(错误2)-路径是错误的。。我试图在互联网上
在运行vue文件时,需要进行npm操作,但我们发现,有时候用的是npm run serve,而有的时候用的是npm run dev,二者有什么区别 在我们运行一些 vue 项目的时候,输入npm ru
我想在 cloud run 上运行一个长时间运行的作业。该任务可能执行超过 30 分钟,并且主要发送 API 请求。cloud run 在大约 20 分钟后停止执行,从指标来看,它似乎没有识别出我的任
我们无法让 SSE 从 Google Cloud Run 上的容器发送。我已经尝试使用一个简单的 SSE 示例( https://github.com/kljensen/node-sse-exampl
直到最近,我一直在执行这个美丽来构建 + 运行一个带有堆栈的项目: stack build && .stack-work/install/x86_64-linux/lts-4.1/7.10.3/bin
我们有一个小脚本,可以抓取网页(约 17 个条目),并将它们写入 Firestore 集合。为此,我们在 Google Cloud Run 上部署了一项服务。 这段代码的执行需要大约 5 秒 when
我是Docker的新手,我知道一种运行交互式容器的方法如下: $ docker run -it image-name bash 要么 $ docker run -it image-name /bin/
Dockerfile 中的多个 RUN 条目之间有什么区别,例如: FROM php:5.6-apache RUN docker-php-ext-install mysqli RUN apt upda
对于来自文档的云运行内存使用情况 ( https://cloud.google.com/run/docs/configuring/memory-limits ) Cloud Run applicati
今天早上我更新了我的 Ubuntu 版本,现在我无法从 eclipse 运行我的应用程序。 问题是,当我单击“运行方式”时出现的列表是空的,我无法运行任何内容。 我该如何解决这个问题? 我能看到的唯一
我正在 intelliJ 上使用 livereload 测试 spring-boot-devtools。我有一个简单的 SpringBootApplication,可以正常工作。 当我从 maven
我是一名优秀的程序员,十分优秀!