鱼C论坛

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

[已解决]语句作用问题

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

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

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

x
  1. system(“pause “)
复制代码

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

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

  6. int main(void) {
  7.     system("ls");
  8.     system("cat main.c");
  9.     system("readelf -l main");
  10.     return 0;
  11. }
  12. sh-5.1$ gcc -m32 -g3 -Wall -o main main.c
  13. sh-5.1$ ./main
  14. main  main.c  read  read.c  write  write.c
  15. #include <stdio.h>
  16. #include <stdlib.h>

  17. int main(void) {
  18.     system("ls");
  19.     system("cat main.c");
  20.     system("readelf -l main");
  21.     return 0;
  22. }

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

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

  41. Section to Segment mapping:
  42.   Segment Sections...
  43.    00
  44.    01     .interp
  45.    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
  46.    03     .init .plt .text .fini
  47.    04     .rodata .eh_frame_hdr .eh_frame
  48.    05     .init_array .fini_array .dynamic .got .got.plt .data .bss
  49.    06     .dynamic
  50.    07     .note.gnu.build-id .note.gnu.property .note.ABI-tag
  51.    08     .note.gnu.property
  52.    09     .eh_frame_hdr
  53.    10
  54.    11     .init_array .fini_array .dynamic .got
  55. sh-5.1$
复制代码

点评

我很赞同!: 5.0
我很赞同!: 5
https://blog.csdn.net/way_back/article/details/122708823 求最佳  发表于 2023-9-28 19:10
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

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

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

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

球一个最佳答案谢谢啦!这对我非常重要!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

评分

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

查看全部评分

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

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

  6. int main(void) {
  7.     system("ls");
  8.     system("cat main.c");
  9.     system("readelf -l main");
  10.     return 0;
  11. }
  12. sh-5.1$ gcc -m32 -g3 -Wall -o main main.c
  13. sh-5.1$ ./main
  14. main  main.c  read  read.c  write  write.c
  15. #include <stdio.h>
  16. #include <stdlib.h>

  17. int main(void) {
  18.     system("ls");
  19.     system("cat main.c");
  20.     system("readelf -l main");
  21.     return 0;
  22. }

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

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

  41. Section to Segment mapping:
  42.   Segment Sections...
  43.    00
  44.    01     .interp
  45.    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
  46.    03     .init .plt .text .fini
  47.    04     .rodata .eh_frame_hdr .eh_frame
  48.    05     .init_array .fini_array .dynamic .got .got.plt .data .bss
  49.    06     .dynamic
  50.    07     .note.gnu.build-id .note.gnu.property .note.ABI-tag
  51.    08     .note.gnu.property
  52.    09     .eh_frame_hdr
  53.    10
  54.    11     .init_array .fini_array .dynamic .got
  55. sh-5.1$
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-9-28 22:28:50 | 显示全部楼层
这条语句相当于你在终端中执行pause命令,里面可以填各种你系统支持的命令
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

也就是说让系统在终端自己给自己写一条指令吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

是的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-4-22 06:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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