鱼C论坛

 找回密码
 立即注册
查看: 554|回复: 7

[已解决]语句作用问题

[复制链接]
发表于 2023-9-28 19:01:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
system(“pause “)
这行语句有什么作用?
最佳答案
2023-9-28 20:45:54
奋斗中的鱼 发表于 2023-9-28 19:03
还有,system()还有什么其他用途吗?
就是说,括号中还可以填什么?

填命令
sh-5.1$ ls
main  main.c  read  read.c  write  write.c
sh-5.1$ cat main.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    system("ls");
    system("cat main.c");
    system("readelf -l main");
    return 0;
}
sh-5.1$ gcc -m32 -g3 -Wall -o main main.c
sh-5.1$ ./main
main  main.c  read  read.c  write  write.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    system("ls");
    system("cat main.c");
    system("readelf -l main");
    return 0;
}

Elf file type is DYN (Position-Independent Executable file)
Entry point 0x1060
There are 12 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x00000034 0x00000034 0x00180 0x00180 R   0x4
  INTERP         0x0001b4 0x000001b4 0x000001b4 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x00000000 0x00000000 0x00428 0x00428 R   0x1000
  LOAD           0x001000 0x00001000 0x00001000 0x00204 0x00204 R E 0x1000
  LOAD           0x002000 0x00002000 0x00002000 0x000d4 0x000d4 R   0x1000
  LOAD           0x002ee8 0x00003ee8 0x00003ee8 0x00128 0x0012c RW  0x1000
  DYNAMIC        0x002ef0 0x00003ef0 0x00003ef0 0x000f0 0x000f0 RW  0x4
  NOTE           0x0001c8 0x000001c8 0x000001c8 0x00078 0x00078 R   0x4
  GNU_PROPERTY   0x0001ec 0x000001ec 0x000001ec 0x00034 0x00034 R   0x4
  GNU_EH_FRAME   0x002028 0x00002028 0x00002028 0x00024 0x00024 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
  GNU_RELRO      0x002ee8 0x00003ee8 0x00003ee8 0x00118 0x00118 R   0x1

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .note.gnu.build-id .note.gnu.property .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt
   03     .init .plt .text .fini
   04     .rodata .eh_frame_hdr .eh_frame
   05     .init_array .fini_array .dynamic .got .got.plt .data .bss
   06     .dynamic
   07     .note.gnu.build-id .note.gnu.property .note.ABI-tag
   08     .note.gnu.property
   09     .eh_frame_hdr
   10
   11     .init_array .fini_array .dynamic .got
sh-5.1$

点评

我很赞同!: 5.0
我很赞同!: 5
https://blog.csdn.net/way_back/article/details/122708823 求最佳  发表于 2023-9-28 19:10
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2023-9-28 19:01:37 | 显示全部楼层
system("pause")语句的作用是在程序执行完毕后暂停命令行窗口,等待用户按下任意键继续。这在调试和开发过程中非常有用,可以防止程序运行结束后窗口立即关闭,以便查看程序输出或调试信息。

具体解释如下:
- system(...)函数是C/C++标准库中的一个函数,用于执行系统命令。
- "pause"是一个系统命令,表示暂停命令行窗口的执行,等待用户按下任意键。
- system("pause")会调用系统命令,执行暂停操作。

然而,请注意,在实际的生产环境中,不建议使用system("pause")这种方式来暂停程序。因为它依赖于特定的操作系统命令,使得代码的可移植性变差。更好的做法是使用跨平台的方式来实现类似的功能,比如使用getchar()函数来等待用户输入。

希望这个解释对你有帮助!如果还有其他问题,请随时提问。

球一个最佳答案谢谢啦!这对我非常重要!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-9-28 19:03:05 | 显示全部楼层
还有,system()还有什么其他用途吗?
就是说,括号中还可以填什么?

评分

参与人数 1荣誉 +1 收起 理由
Mike_python小 + 1 加好友,回帖限制了

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-9-28 20:45:54 | 显示全部楼层    本楼为最佳答案   
奋斗中的鱼 发表于 2023-9-28 19:03
还有,system()还有什么其他用途吗?
就是说,括号中还可以填什么?

填命令
sh-5.1$ ls
main  main.c  read  read.c  write  write.c
sh-5.1$ cat main.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    system("ls");
    system("cat main.c");
    system("readelf -l main");
    return 0;
}
sh-5.1$ gcc -m32 -g3 -Wall -o main main.c
sh-5.1$ ./main
main  main.c  read  read.c  write  write.c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    system("ls");
    system("cat main.c");
    system("readelf -l main");
    return 0;
}

Elf file type is DYN (Position-Independent Executable file)
Entry point 0x1060
There are 12 program headers, starting at offset 52

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  PHDR           0x000034 0x00000034 0x00000034 0x00180 0x00180 R   0x4
  INTERP         0x0001b4 0x000001b4 0x000001b4 0x00013 0x00013 R   0x1
      [Requesting program interpreter: /lib/ld-linux.so.2]
  LOAD           0x000000 0x00000000 0x00000000 0x00428 0x00428 R   0x1000
  LOAD           0x001000 0x00001000 0x00001000 0x00204 0x00204 R E 0x1000
  LOAD           0x002000 0x00002000 0x00002000 0x000d4 0x000d4 R   0x1000
  LOAD           0x002ee8 0x00003ee8 0x00003ee8 0x00128 0x0012c RW  0x1000
  DYNAMIC        0x002ef0 0x00003ef0 0x00003ef0 0x000f0 0x000f0 RW  0x4
  NOTE           0x0001c8 0x000001c8 0x000001c8 0x00078 0x00078 R   0x4
  GNU_PROPERTY   0x0001ec 0x000001ec 0x000001ec 0x00034 0x00034 R   0x4
  GNU_EH_FRAME   0x002028 0x00002028 0x00002028 0x00024 0x00024 R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x10
  GNU_RELRO      0x002ee8 0x00003ee8 0x00003ee8 0x00118 0x00118 R   0x1

 Section to Segment mapping:
  Segment Sections...
   00
   01     .interp
   02     .interp .note.gnu.build-id .note.gnu.property .note.ABI-tag .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt
   03     .init .plt .text .fini
   04     .rodata .eh_frame_hdr .eh_frame
   05     .init_array .fini_array .dynamic .got .got.plt .data .bss
   06     .dynamic
   07     .note.gnu.build-id .note.gnu.property .note.ABI-tag
   08     .note.gnu.property
   09     .eh_frame_hdr
   10
   11     .init_array .fini_array .dynamic .got
sh-5.1$
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-9-28 22:28:50 | 显示全部楼层
这条语句相当于你在终端中执行pause命令,里面可以填各种你系统支持的命令
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-9-29 15:40:53 | 显示全部楼层
liuhongrun2022 发表于 2023-9-28 22:28
这条语句相当于你在终端中执行pause命令,里面可以填各种你系统支持的命令

也就是说让系统在终端自己给自己写一条指令吗?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-9-29 18:16:23 | 显示全部楼层
奋斗中的鱼 发表于 2023-9-29 15:40
也就是说让系统在终端自己给自己写一条指令吗?

是的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 01:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表