|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- /*使用if else语句编写一个程序读入输入,读到#停止。用感叹号替换句号,用两个感叹号替换原来的感叹号,最后报告进行了多少次替换*/
-
- #include<stdio.h>
- int main(void)
- {
- char ch;
- int flag = 0;
-
- printf("Please enter some words:\n");
- while((ch = getchar()) != '#')
- {
- if(ch == '.')
- {
- ch = '!';
- flag++;
- }
- if else (ch == '!')
- {
- putchar(ch);
- flag++;
- }
- putchar(ch);
- }
- printf("\nThere is %d changs in this program.",falg);
-
- return 0;
- }
复制代码
这个代码为什么报以下错误?
ex4.c: In function ‘main’:
ex4.c:17:6: error: expected ‘(’ before ‘else’
if else (ch == '!')
^
PS:怎么从vim里面复制代码的时候不选取旁边的行号?我用v模式复制了以后又不能全局粘贴到网上。求助啊啊 啊
- /*使用if else语句编写一个程序读入输入,读到#停止。
- 用感叹号替换句号,用两个感叹号替换原来的感叹号,最后报告进行了多少次替换*/
- #include<stdio.h>
- int main(void)
- {
- char ch;
- int flag = 0;
- printf("Please enter some words:\n");
- while((ch = getchar()) != '#')
- {
- if(ch == '.')
- {
- ch = '!';
- flag++;
- }
- else if(ch == '!')
- {
- putchar(ch);
- flag++;
- }
- putchar(ch);
- }
- printf("\nThere is %d changs in this program.", flag);
- return 0;
- }
复制代码
- Please enter some words:
- your. your!#
- your! your!!
- There is 2 changs in this program.请按任意键继续. . .
复制代码
|
|