"响应命令行变元",dev-c++无法编译,vc6可以

liushac 2009-09-21 03:14:49

/***********************************************************************
Copyright (c) 2009,liushac
All rights no reserved.

Name: <<C程序设计语言>>例程5-10
ID: hello.c
功能: 回应命令行变元,打印与第一个变元指定的模式串匹配的行。

Version: 0.1
Author: c.
Date: Sep 21, 2009

***********************************************************************/
#include <stdio.h>
#include <string.h>

#define MAXLINE 1000
int getline(char *line, int max);

int main(int argc, char *argv[ ])
{
char line[MAXLINE];
int found = 0;
if (argc != 2)
{
printf ("usage: hello.exe findme\n");
printf ("input:hello,world\n");
printf ("input:please findme\n");
printf ("display:please findme\n\n");
printf ("---------------------------\n");
}
else
{
while (getline(line, MAXLINE) > 0)
{
if (strstr(line, argv[1]) != NULL) /* 标准库函数strstr(s, t)用于返回子字符串t在字符串s中第一次出现处的指针;如果

子字符串t未在字符串s中出现过,那么返回值为空指针。它在头文件<string.h>中说明 */
{
printf ("---------------------------\n");
printf("ok.find \"%s\" of the line.\n%s\n", argv[1],line);
found++;
}
}
}
return found;
}
/* getline:将一行读入s中并返回其长度 */
int getline (char s[],int lim)
{
int c;
int i;
i=0;

while (i<lim-1 && (c=getchar())!=EOF && c!='\n'){
s[i]=c;
++i;
}
if (c=='\n'){
s[i]=c;
++i;
}
s[i]='\0';
return i;
}

dev-c++无法编译,点击编译后进程处于假死状态,vc6可以编译,这是什么原因?
...全文
204 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
liushac 2009-09-25
  • 打赏
  • 举报
回复
重装dev-c++还是有问题,有可能是系统的问题,拿vc6先顶着。感谢上面几位,结贴了。
liushac 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 cuiy0001 的回复:]
代码没有问题,我的可以编译,,不过我devC++编译时麽有ld.exe collect32.exe
以前我装过两个不同版本的,结果无限混乱。

楼主注意下DevC的安装目录没有空格,将compiler options 初始化。
[/Quote]
不胜感激,我再试一下
序员 2009-09-21
  • 打赏
  • 举报
回复
代码没有问题,我的可以编译,,不过我devC++编译时麽有ld.exe collect32.exe
以前我装过两个不同版本的,结果无限混乱。

楼主注意下DevC的安装目录没有空格,将compiler options 初始化。
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 liushac 的回复:]
引用 10 楼 pmerofc 的回复:
C/C++ code#include <stdio.h>
#include <stdlib.h>int main(int argc,char*argv[])
{
 
  system("PAUSE");return0;
}
这个呢?

个别时候能编译:
开始不能编译,重打开dev-c++可以编译,再次编译又不行了;再次重新打开dev-c++这次又无法编译了,
编译时,进程中有ld.exe和collect2.exe,感觉是运行到collect2.exe假死了
[/Quote]
不胜同情

爱莫能助
liushac 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 pmerofc 的回复:]
C/C++ code#include<stdio.h>
#include<stdlib.h>int main(int argc,char*argv[])
{

system("PAUSE");return0;
}
这个呢?
[/Quote]
个别时候能编译:
开始不能编译,重打开dev-c++可以编译,再次编译又不行了;再次重新打开dev-c++这次又无法编译了,
编译时,进程中有ld.exe和collect2.exe,感觉是运行到collect2.exe假死了
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 liushac 的回复:]
忘了什么时候在电脑中安装了两遍dev-c++,把两个都卸载了,重新运行devcpp-4.9.9.2_setup.exe安装,安装后编译下面的正常
#include <stdio.h>

int main()
{
    printf ("hello,world");
    return 0;
}
但还是不能编译顶上的代码,要崩溃了
[/Quote]
还是 显示compiling...?
liushac 2009-09-21
  • 打赏
  • 举报
回复
忘了什么时候在电脑中安装了两遍dev-c++,把两个都卸载了,重新运行devcpp-4.9.9.2_setup.exe安装,安装后编译下面的正常
#include <stdio.h>

int main()
{
printf ("hello,world");
return 0;
}
但还是不能编译顶上的代码,要崩溃了
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{

system("PAUSE");
return 0;
}

这个呢?
liushac 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 pmerofc 的回复:]
编译一下"hello,world"看行不行
若行,也可能有些编译参数设置的不对

[/Quote]
啊,还是不行!下面这个都无编译
#include <stdio.h>

int main()
{
printf ("hello,world");
return 0;
}
无法编译
liushac 2009-09-21
  • 打赏
  • 举报
回复
看到帮助里有这么一句:
You must enable 'Generate profiling info for analysis'in Compiler Options
试着设置了一下,现在似乎正常了,汗...
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
编译一下"hello,world"看行不行
若行,也可能有些编译参数设置的不对
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 liushac 的回复:]
是无法compile,显示compiling...
[/Quote]
那一定是别的问题
不是代码的问题
是否你的dev c++没安装好?
liushac 2009-09-21
  • 打赏
  • 举报
回复
是无法compile,显示compiling...
pmerOFc 2009-09-21
  • 打赏
  • 举报
回复
楼主两次输入不一样吧
麻烦楼主报一下输入
序员 2009-09-21
  • 打赏
  • 举报
回复
我用DevC++ 试了一下,完全可以。。。
liushac 2009-09-21
  • 打赏
  • 举报
回复
反复试了下,重启电脑后dev-c++可以编译,再次编译时又没有响应了,搞不清楚是哪里出问题了
james_hw 2009-09-21
  • 打赏
  • 举报
回复
帮顶一下

69,379

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧