小编Lin*_*van的帖子

添加额外的int时,C程序崩溃

我是C新手并使用Eclipse IDE以下代码可以正常工作:

#include <stdio.h>
#include <stdlib.h>
#include <String.h>
int main()
{
    char *lineName;
    int stationNo;
    int i;
    while (scanf("%s (%d)", lineName, &stationNo)!=EOF) {
        for (i=0; i<5 ; i++ ){
            printf("%d %d",i);
        }
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输入:

Green (21)

Red (38)
Run Code Online (Sandbox Code Playgroud)

输出:

Green (21)

Red (38)
0123401234
Run Code Online (Sandbox Code Playgroud)

但是,只需添加一个新的int:

#include <stdio.h>
#include <stdlib.h>
#include <String.h>
int main()
{
    char *lineName;
    int stationNo;
    int i,b=0;
    while (scanf("%s (%d)", lineName, &stationNo)!=EOF) {
        printf("%d",b);
        for (i=0; i<5 ; i++ ){
            printf("%d",i);
        }
    }
    return …
Run Code Online (Sandbox Code Playgroud)

c

0
推荐指数
1
解决办法
179
查看次数

标签 统计

c ×1