Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

C 语言实现字符串切片 | Qiming's Blog #4

Open
xqm32 opened this issue Jan 9, 2022 · 0 comments
Open

C 语言实现字符串切片 | Qiming's Blog #4

xqm32 opened this issue Jan 9, 2022 · 0 comments

Comments

@xqm32
Copy link
Owner

xqm32 commented Jan 9, 2022

https://xqm32.github.io/posts/slicing-string-in-c-language/

搬运一篇笔者在知乎发的文章:C 语言实现字符串切片
基于 Python 的切片的格式实现的 C 语言字符串切片:
#include <ctype.h>#include <stdio.h>#include <stdlib.h>#include <string.h> typedef long long SizeType; size_t fgetln(FILE* stream, char* dest, size_t size) { size_t i; for (i = 0, *dest = fgetc(stream); *dest != '\n' && !feof(stream) && --size > 0; ++i, ++dest = fgetc(stream)) ; dest = '\0'; return i; } // 读取一行字符串。 size_t slice(char from, char to, SizeType begin, SizeType end, SizeType interval) { SizeType i; begin += begin < 0 ?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant