这是 2 个独立的应用程序。
emp.bin.我尝试分别打印每个字符,结果发现名称中的每个字母后面都有 3 个空字符 '\n',这就是它不在第一个字符后面打印的原因。
“编写”应用程序代码:
//Receives records from keyboard and writes them to a file in binary mode
#include <stdio.h>
int main()
{
FILE *fp;
char another = 'Y';
struct emp
{
char name[40];
int age;
float bs;
};
struct emp e;
fp = fopen("emp.bin", "wb");
if (fp == NULL)
{
puts("Cannot open the file.");
return 1;
}
while(another == 'Y')
{
printf("Enter the employee name, age and salary: ");
scanf("%S %d %f", …Run Code Online (Sandbox Code Playgroud) 它在 VS Code 中运行良好,但在 powershell 中它会提示用户输入,但不会在“stdout”中显示字符串。这是示例代码:
import sys
def get_int():
sys.stdout.write("Enter number(s). ")
return map(int, sys.stdin.readline().strip().split())
def get_float():
sys.stdout.write("Enter number(s). ")
return map(float, sys.stdin.readline().strip().split())
def get_list_of_int():
sys.stdout.write("Enter numbers followed by space. ")
return list(map(int, sys.stdin.readline().strip().split()))
def get_string():
sys.stdout.write("Enter string. ")
return sys.stdin.readline().strip()
a, b, c, d = get_int()
e, f, g = get_float()
arr = get_list_of_int()
str = get_string()
Run Code Online (Sandbox Code Playgroud) 我正在运行 64 位机器。如果我输入getsizeof(int()),我会得到 24。使用这 24 个字节的元素或对象是什么?下面是一些更令人困惑的结果:
getsizeof(0)returns 24.
getsizeof(1)returns 28. 为什么 1 比 0 多占用 4 个字节?并getsizeof(1.5)返回 24。为什么浮点数 1.5 的大小比整数 1 小。
python ×2
binaryfiles ×1
c ×1
file-pointer ×1
pointers ×1
powershell ×1
python-3.x ×1
scanf ×1