linux下用C编程的时候的换行问题

linux下用C编程的时候的换行问题,第1张

你的键盘layout设置不对 应该设置成默认的 us

我都说了 你linux的键盘layout设置不对啊

不行你打开个编辑器 把键盘上的键按一遍 肯定有很多跟键位不符的,

直接上google搜索符合你发行版的重新设定键盘区域的方法

Linux下可以用strstr()函数定位子串所在的位置,用来实现用子串分隔一个字符串。man strstr可以看函数相关介绍

$ man strstr

NAME

       strstr - locate a substring

SYNOPSIS

       #include <string.h>

       char *strstr(const char *haystack, const char *needle)

DESCRIPTION

       The  strstr()  function finds the first occurrence of the substring needle in the string haystack.  The terminating `\0' characters are not compared.

       strstr()函数实现从haystack串中,查找第一次出现的needle子串,只比较有效字符,结束符\0不算在内。

如:

#include <stdio.h>

#include <string.h>

int main()

{

    char s[]="abc@#123@#def@456@#ghi#789"

    char sub[]="@#"

    char *pc,*pb

    pb=pc=s  //pb指向字符串头

    while( pc=strstr(pc,sub) ) //查找匹配字符串位置

    {

        *pc='\0' //置字符串结束符

        puts(pb) //输出当前字符串

        pc+=strlen(sub) //跳过分隔符串

        pb=pc //pb指向新的起始位置

    }

    if ( pb )

        puts(pb)

    return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8943790.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-23
下一篇2023-04-23

发表评论

登录后才能评论

评论列表(0条)

    保存