我正在试图弄清楚如何在C中切割一部分字符串.例如,你有这个字符串"狗死了,因为一辆车在过马路时撞到了他"一个函数如何制作句子"a过马路时撞到他的车"还是"一辆车撞到了他"
你如何使用C的库(或/和)自定义函数来解决这个问题?
好吧,我没有主要代码,但这将是这个实验的结构
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include "display_usage.c"/*If the user enters wrong arguments it will tell them how it should be */
void cut( const char *file, int option, int first, int last );
int main(int argc, char *argv[] ) {
FILE *fp;
char ch;
fp = fopen("test.txt", "r"); // Open file in Read mode
while (ch!=EOF) {
ch = fgetc(fp); // Read a Character
printf("%c", ch);
}
fclose(fp); // Close …Run Code Online (Sandbox Code Playgroud)