全心思齐网

c语言运行后为什么出现n多的烫烫烫烫烫?

这是因为你没有赋值串尾标记'\0'。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

#include<stdio.h>

#include<string.h>

int main(void)

{int i,j,n;

char a[100],b[100];

scanf("%s",a);

n=strlen(a);

for(i=0;i<n;i++)

if(a[i]!='*')

{ b[j]=a[i]; j++; }

b[j]='\0';

printf("%s",b);

return 0;

}

匿名回答于2024-05-25 17:19:41


你好,我对你这个程序修改之后,已经OK

至于为什么出现n多的烫,是因为char类型的数组,结束的时候需要对最后一个字符赋值为'\0'

具体代码如下

// #include <iostream>

// using namespace std;

//

// // 类模板的参数

// template <typename C>

// class A // 普通类

// {

// public:

// // 构造函数模板

// // 与整个类的模板没有关系

// template <typename T2>

// A(T2 v1, T2 v2);

//

// template <typename T>

// // 成员函数模板

// void myft(T tmpt)

// {

// cout << tmpt << endl;

// }

//

// // 普通成员函数

// template <typename T2>

// void myfunc(T2 v1, T2 v2);

//

// C m_ic; // 类模板变量

// };

//

// // 先跟类的模板参数列表

// template <typename C>

// // 再跟构造函数自己的模板参数列表

// template <typename T2>

// A<C>::A(T2 v1, T2 v2)

// {

// cout << v1 << v2 << endl;

// }

//

// // 先跟类的模板参数列表

// template <typename C>

// // 再跟构造函数自己的模板参数列表

// template <typename T2>

// void A<C>::myfunc(T2 v1, T2 v2)

// {

//

// }

//

// // 显式实例化手段中的实例化定义,这种实例化只需在一个.cpp

// // 文件中写就可以

// // 编译器遇到这段代码就直接实例化一个A<float>

// template A<float>;

// //template void myfunc(int v1, int v2);

//

// // 显式实例化手段中的实例化声明

// // 在一个文件中实例化,其他文件全部为声明

// // extern template A<float>;

// // extern作用:不会在在本文件中生成一个extern后面所表示的模板的实例化代码

// // extern目的:告诉编译器,在其他的源文件(.cpp)中已经有了一个改该模板的实例化版本了。

//

//

// int main()

// {

// A<float> a(1, 2);

//

// A<float> b(1.1, 2.2);

//

// return 0;

// }

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>

#include <string.h>

#include <stdlib.h>

int main(void)

{

int i,j=0,n;

char a[100],b[100];

scanf("%s",a);

n=strlen(a);

for(i=0;i<n;i++)

{

if(a[i]!='*')

{

b[j]=a[i];

j++;

}

}

b[j] = '\0';

printf("%s",b);

system("pause");

return 0;

}

运行结果如下


我是奕双,现在已经毕业将近两年了,从大学开始学编程,期间学习了C需要编程,C++需要编程,Win32编程,MFC编程,毕业之后进入一家图像处理相关领域的公司,掌握了用OpenCV对图像进行处理,如果大家对相关领域感兴趣的话,可以关注我,我这边会为大家进行解答哦!如果大家需要相关学习资料的话,可以私聊我哦!

匿名回答于2024-04-18 23:09:13


在printf("%s",b)前面加

b[j]='\0'

匿名回答于2024-04-19 03:14:44


字符数组用字符串格式打印要在结尾加\0!这好比你让一个机器人往你拿着的杯子里倒开水,你不告诉他什么时候停,你可不就得喊烫烫烫烫烫烫!局部数组初始化是个好习惯!

匿名回答于2024-04-19 03:32:14


编译器为了实现断点调试,会在代码内存中插入int 0x3指令,该指令值是0xcc,多个0xcc的编码是中文“烫”

匿名回答于2024-04-19 10:34:52


相关知识问答