c语言怎样截取字符串

 时间:2026-02-14 08:47:58

1、直接给大家代码吧:

#include<stdio.h>

#include<string.h>

#include<ctype.h>

void print(char s[],int n,int m)

{

    int k;

    int i;

    char *p;

    k=strlen(s);

    p = s;

c语言怎样截取字符串

2、    for(i=n-1;i<n-1+m;i++)//从第n-1位置开始,截取m个字符

        putchar(*(p+i));

    printf("\n");

  

}

void main()

{

    char *s,str[20];

    int m,n;

    printf("please input a string:\n");

    s = str;

    gets(s);

    printf("the string is:");

    puts(s);

    printf("please input n and m\n");

    scanf("%d%d",&n,&m);

    print(s,n,m);

}

c语言怎样截取字符串

3、题目要调用这个函数:

viod substr(char *source,int start,intlength,char *dest);

// cscs.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include<stdio.h>

#include<string.h>

#include<ctype.h>

void substr(char *source,int start,int length,char *dest);

int main()

{

c语言怎样截取字符串

4、   char a[20],b[20],*p;

    int n,x,i;

    printf("how long:");

    scanf("%d",&n);

    printf("where:");

    scanf("%d",&x);

    getchar();

    printf("input words:");

    gets(a);

    p = a;

    substr(p,x,n,b);

    return 0;

}

c语言怎样截取字符串

5、void substr(char *source,int start,int length,char *dest)

{

    int k;

    int i;

    int j=0;

    char *p;

    k=strlen(source);

    p = source;

    for(i=start-1;i<start-1+length;i++)//从第n-1位置开始,截取m个字符

        dest[j++] = *(p+i);

    dest[j] = '\0';

    printf("the new string is:");

    puts(dest);

    printf("\n");

   

}

c语言怎样截取字符串

  • 如何用C++进行函数的调用?
  • 怎么查看CMD指令的使用方法和示例?
  • 【校园指南】东莞理工学院城市学院奖学金攻略
  • QT如何清空文本中的空白
  • C-Free5如何设置代码提示显示符号工具条
  • 热门搜索
    丝瓜藤的功效与作用 uk是什么意思 万里无云的意思 一望无际的意思 卵黄囊什么时候出现 相敬如宾的意思 结息是什么意思 今夕何夕是什么意思 葛根的功效和作用 索然无味的意思