如题,哪位能给解释下吗?
我在C程序里调用scanf();
char * s;
. . . .
scanf("%s",s);
. . . .
一到这儿,就会有段错误出来。
[问题]scanf 段错误
-
- 帖子: 13
- 注册时间: 2006-10-14 12:49
- jiangpeng
- 帖子: 223
- 注册时间: 2006-07-25 9:33
- 联系:
不知道...里面有没有malloc哟
Take what man makes and use it, But do not worship it, For it shall pass. -- Anonymous
Twitter @jiangpeng
Twitter @jiangpeng
-
- 帖子: 13
- 注册时间: 2006-10-14 12:49
没有malloc,只是调用了scanf()
今天又有这种错误出现了。
看来是程序中指针有问题。代码如下:
期待解决!
今天又有这种错误出现了。
看来是程序中指针有问题。代码如下:
代码: 全选
#include<stdio.h>
5
6 int** func(){
7 int i = 0;
8 int j = 0;
9 int sum = 0;
10 static int **a;
11 int index1 = 0;
12 int index2 = 0;
13 for(i = 1;i <= 3;i ++){
14 a[index1][index2] = i;
15 for(j = 1;j <= 5;j ++){
16 a[index1][index2] = j;
17 a[index1][index2] = 8 - i - j;
18 sum ++;
19 a[index1][index2] = sum;
20 index1 ++;
21 index2 = 0;
22 }
23 a[index1][0] = -1;/*用于标记数组是否结束*/
24 }
25 return a;
26 }
27
28 /* main */
29 int main(){
30 int **a;
31 int index = 0;
32 a = func();
33 while(a[index][0] != -1){
34 printf("%3d%3d%3d",a[index][0],a[index][1],a[index][2]);
35 index ++;
36 }
37 }
老怪