C<3.1>getchar,char参与计算特性

int main()
{
	int j, k; char cp;
	cp=getchar();
	printf("%d,%d,%d\n", cp>'A',cp-'A',cp+1);

	return 0;
}

B的ASCLL码66

输入B,输出>>>1,1,67

一个小尝试

#include<stdio.h>
#include<string.h>
int main()
{
	char a='d';
	do
		putchar(a);
	while (a=getchar());
	printf("%c", a);
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以为你提供一个基本的行编辑器的C语言代码。代码如下: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE_LENGTH 1000 #define MAX_LINES 1000 #define PAGE_SIZE 20 char* lines[MAX_LINES]; int current_line = 0; int line_count = 0; void insert_line(int line_number, char* text) { if (line_number < 0 || line_number > line_count) { printf("Invalid line number\n"); return; } if (line_count == MAX_LINES) { printf("Maximum number of lines reached\n"); return; } if (line_number == line_count) { lines[line_number] = malloc(strlen(text) + 1); strcpy(lines[line_number], text); } else { for (int i = line_count; i > line_number; i--) { lines[i] = lines[i - 1]; } lines[line_number] = malloc(strlen(text) + 1); strcpy(lines[line_number], text); } line_count++; } void delete_lines(int start_line, int end_line) { if (start_line < 0 || start_line >= line_count) { printf("Invalid starting line number\n"); return; } if (end_line < 0 || end_line >= line_count) { printf("Invalid ending line number\n"); return; } if (end_line < start_line) { printf("Invalid line range\n"); return; } for (int i = start_line; i <= end_line; i++) { free(lines[i]); } for (int i = end_line + 1; i < line_count; i++) { lines[i - (end_line - start_line + 1)] = lines[i]; } line_count -= (end_line - start_line + 1); if (current_line >= line_count) { current_line = line_count - 1; } } void switch_buffer(FILE* input, FILE* output) { for (int i = 0; i < line_count; i++) { fprintf(output, "%s\n", lines[i]); free(lines[i]); lines[i] = NULL; } line_count = 0; current_line = 0; char line[MAX_LINE_LENGTH]; while (fgets(line, MAX_LINE_LENGTH, input) != NULL) { if (strcmp(line, ".\n") == 0) { return; } insert_line(line_count, line); } } void display_lines() { int page_count = line_count / PAGE_SIZE; if (line_count % PAGE_SIZE != 0) { page_count++; } for (int i = 0; i < page_count; i++) { int start_line = i * PAGE_SIZE; int end_line = start_line + PAGE_SIZE - 1; if (end_line >= line_count) { end_line = line_count - 1; } for (int j = start_line; j <= end_line; j++) { printf("%04d %s", j, lines[j]); } if (end_line < line_count - 1) { printf("--More--\n"); char c = getchar(); while (c != '\n') { c = getchar(); } } } } int main(int argc, char* argv[]) { if (argc != 3) { printf("Usage: %s <input_file> <output_file>\n", argv[0]); return 0; } FILE* input = fopen(argv[1], "r"); FILE* output = fopen(argv[2], "w"); if (input == NULL) { printf("Error opening input file\n"); return 0; } if (output == NULL) { printf("Error opening output file\n"); return 0; } char line[MAX_LINE_LENGTH]; while (fgets(line, MAX_LINE_LENGTH, input) != NULL) { if (strcmp(line, "n\n") == 0) { switch_buffer(input, output); } else if (strcmp(line, "p\n") == 0) { display_lines(); } else if (line[0] == 'i') { int line_number = atoi(&line[1]); char text[MAX_LINE_LENGTH]; fgets(text, MAX_LINE_LENGTH, input); insert_line(line_number, text); } else if (line[0] == 'd') { int start_line = atoi(&line[1]); int end_line = start_line; char* end_line_str = strchr(line, ' '); if (end_line_str != NULL) { end_line = atoi(end_line_str + 1); } delete_lines(start_line, end_line); } else { printf("Invalid command\n"); } } fclose(input); fclose(output); return 0; } ``` 该行编辑器实现了四个基本编辑命令,包括行插入、行删除、活区切换和活区显示。你可以通过输入相应的命令和参数来操作它。在实现中,我们使用了一个字符串数组来存储所有的行,并使用一个变量来追踪当前活区中的行数和当前行的位置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值