| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1007 人关注过本帖
标题:[求助]请教一个命令行的问题!
只看楼主 加入收藏
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 

#include <stdio.h>
#include <string.h>
#define N 1000

int main(void)
{
char ch, str[N];
int i = 0;

while(1)
{
ch = getchar();
while(ch != EOF)
{
str[i] = ch;
i ++;
if(ch == '\n')
break;
ch = getchar();
}
if(ch == EOF)
break;
else if(str[5] == '-')
printf("I am showing help.\n");
else if(str[5] == 'e'||str[5] == 'o')
printf("I am a c89 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"a.exe\".\n");
else if(str[5] == 'c')
printf("I am a c89 preprocessor + compiler. I start from \"hello.c\" and end with \"hello.o\".\n");
else if(str[5] == 'E')
printf("I am a c89 preprocessor. I start from \"hello.c\" and end with \"expanded.c\".\n");
else
{
if(str[14] == 'e')
printf("I am a c99 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"a.exe\".\n");
else if(str[14] == 'c')
printf("I am a c99 preprocessor + compiler. I start from \"hello.c\" and end with \"hello.o\".\n");
else if(str[14] == 'o')
printf("I am a c99 preprocessor. I start from \"hello.c\" and end with \"foobar.c\".\n");
}
i = 0;
}

return 0;

}
这是我写的一段代码!我知道有很多错误!


该学习了。。。
2006-11-30 18:10
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 
gcc -std=c99 -o foobar.c -E hello.c在这里我糊涂了!请说明一下!谢谢了!

该学习了。。。
2006-11-30 18:27
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1000

int main(void)
{
char str[N], ch;
int i = 0;
int string(char str[N]);

while(1)
{
ch = getchar();
while(ch != EOF)
{
str[i] = ch;
i ++;
ch = getchar();
if(ch == '\n')
break;
}
if(ch == EOF)
break;
else
string(str);
i = 0;
}

return 0;
}

int string(char str[N])
{
int i, length ,word = 0;

length = strlen(str);
for(i = 0;i < length;i ++)
{
if(str[5] == '-'&&word == 0)
{
printf("I am showing help.\n");
word = 1;
}
else if(str[5] == 's')
{
if((strcmp(&str[i], "-") == 0)&&(strcmp(&str[i+1], "E") == 0)&&word == 0)
{
printf("I am a c99 preprocessor. I start from \"hello.c\" and end with \"foobar.c\".\n");
word = 1;
}


}
}

return 0;
}

我想问一下!为什么红色部分的总也不执行啊?


该学习了。。。
2006-12-01 12:52
zhanghuan_10
Rank: 1
等 级:新手上路
威 望:2
帖 子:751
专家分:0
注 册:2006-10-25
收藏
得分:0 

还是有错误啊!我无语!看来只能得60分了!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 1000

int main(void)
{
char str[N], ch;
int i = 0;
int string(char str[N], int k);

while(1)
{
str[N] = 'a';
ch = getchar();
while(ch != EOF)
{
str[i] = ch;
i ++;
ch = getchar();
if(ch == '\n')
break;
}
if(ch == EOF)
break;
else
string(str, i - 1);
i = 0;
}

return 0;

}

int string(char str[N], int k)
{
int i, word = 0, j, n = 0, m = 0;

if(str[5] == 's')
{
for(i = 0;i < k;i ++)
{
if(str[i] == '-'&&str[i + 1] == 'o')
{
for(j = 0;j < k;j ++)
{
if(str[j] == '-'&&str[j + 1] == 'E'&&word == 0)
{
printf("I am a c99 preprocessor. I start from \"hello.c\" and end with \"expanded.c\".\n");
word = 1;
}
else if(str[j] == '-'&&str[j + 1] == 'c'&&word == 0)
{
printf("I am a c99 preprocessor + compiler. I start from \"hello.c\" and end with \"hello.o\".\n");
word = 1;
}
else if(word == 0)
{
m ++;
}
}
}
}
if(word == 0)
{
printf("I am a c99 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"a.exe\".\n");
word = 1;
}
else if(m == k)
{
printf("I am a c99 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"hello.exe\".\n");
}

}
else if(str[5] == '-')
{
printf("I am showing help.\n");
}
else if(str[4] != '-')
{
printf("I am a c89 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"a.exe\".\n");
}
else
{
for(i = 0;i < k;i ++)
{
if(str[i] == '-'&&str[i + 1] == 'o')
{
for(j = 0;j < k;j ++)
{
if(str[j] == '-'&&str[j + 1] == 'E'&&word == 0)
{
printf("I am a c89 preprocessor. I start from \"hello.c\" and end with \"expanded.c\".\n");
word = 1;
}
else if(str[j] == '-'&&str[j + 1] == 'c'&&word == 0)
{
printf("I am a c89 preprocessor + compiler. I start from \"hello.c\" and end with \"hello.o\".\n");
word = 1;
}
else if(word == 0)
{
n ++;
}
}
}
}
if(n == k)
{
printf("I am a c89 preprocessor + compiler + linker. I start from \"hello.c\" and end with \"hello.exe\".\n");
}
}

return 0;

}


该学习了。。。
2006-12-03 13:15
快速回复:[求助]请教一个命令行的问题!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016883 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved