`
ylxg12345
  • 浏览: 4497 次
  • 性别: Icon_minigender_1
  • 来自: 沈阳
社区版块
存档分类
最新评论

杭电 ASCII 1.2.7

阅读更多

       今天做题,再次碰到了指针的问题,用了不同的编译器,会有不同的反映。在C-Free下处理没有问题了,提交后出现了 ACCESS_VIOLATION 的问题,于是又换了Code::Blocks 出现了问题,但是不懂如何debug,还请大神帮忙分析下。。。。。

题目链接:http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=1&sectionid=2&problemid=23


 

Problem Description
Since all we know the ASCII code, your job is simple: input numbers and output corresponding messages.
 
Input
The first line contains one integer T (1<=T<=1000).
The input will contain T positive integers separated by whitespaces (spaces, newlines, TABs).
The integers will be no less than 32.
 
Output
Output the corresponding message in just one line.
Warning: no extra characters are allowed.
 
Sample Input
13
72 101 108 108 111 44
32 119 111 114 108 100 33
 
Sample Output
Hello, world!
 


代码区:

我的问题代码:

#include"stdio.h"
#include"string.h"
int main(){
	char a[1000],*b;
	int i,j,k;
	scanf("%d",&i);
	//程序代码出错段 start
	for(j=0;j<i;j++){
		scanf("%d",b);
		strcat(a,b);
	}
	//end
	printf("%s",a);
}

 

没有使用指针的正确代码:

#include"stdio.h"
int main(){
	int a[1000];
	int i,j;
	scanf("%d",&i);
	for(j=0;j<i;j++){
		scanf("%d",&a[j]);
	}
	for(j=0;j<i;j++){
		printf("%c",a[j]);
	}
}

 

我的猜想:可能是scanf函数中在获取char型数据时在类型转换上的内存问题

 

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics