c语言 指针 地址溢出,堆栈溢出,指针在C中

我是C的新手,我正在尝试一些我发现的练习.

在其中一个练习中,我正在尝试使用指向字符串的指针(char数组),但它不起作用.它编译,但是当执行时,它会抛出"堆栈溢出"(好吧,我认为是"堆栈溢出",因为我用西班牙语).

这些是有问题的线:

//This is the variable declaration, before this, there is the "main function" declaration

char entrada[100];

char *ult=entrada;

char cantidadstr[10];

int i,j,k = 0;

int res;

scanf ("%s",entrada);

printf ("\n%s",entrada);

//Here crashes

printf ("Hola %s",ult);

while (*ult != "\0"){

//And here there's more code

先感谢您!!

编辑

(我不能回答:))然后,我会发布一些代码.

当我执行时,插入数据后,它会抛出"Violacióndesegmento",谷歌说这意味着Stack Overflow

#include

#include

#include

int main(void){

char entrada[1001*11*101];

/*Asi tenemos el tamano maximo:

1001 por las 1000 posibles lineas, mas la primera

11 por el tamano maximo del numero (1 + 9 ceros), mas el espacio o salto de linea siguiente

101 por el numero de numeros por linea, mas el primero

*/

char *ult=entrada;

char cantidadstr[10];

int i,j,k = 0;

int res;

memset (entrada,'\0',1001*11*101);

scanf ("%s",entrada);

printf ("\n%s",entrada);

//poniendo ese print ahi arriba, ese me lo muestra, por tanto, el fallo esta en el puntero de debajo de esta linea

printf ("Hola %s",ult);

while (*ult != "\0"){

if(*ult == "\n"){

if(i != 0){

printf("\n");

}

i++;

j = 0;

}

else if(i != 0){

if(*ult == " "){

j++;

k=0;

res = atoi(cantidadstr);

printf("%d ",res*2);

//Este es el otro cambio que hablaba

cantidadstr[10] = '\0';

}

else if(j != 0){

cantidadstr[k] = *ult;

}

}

k++;

*ult++;

}

return 0;

}

这是完整的代码,其他论坛的西班牙语评论."entrada"的大小足以支持练习中发送的任何数据.刚刚添加了"memset".第二条评论显示它崩溃的地方

谢谢你们的快速响应!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值