4.5题目: 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
2017-04-03 14:59
453 查看
/*题目: 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.提示:帧头和帧尾分别是head和tail 字串”asdheadhauboisoktail”中headhauboisoktail是合法帧*/
#include <stdio.h>
#include <string.h>
int fun(char *ptr,char *head,char *tail)
{
char *temp;
while(*ptr != '\0')
{
if(strncmp(ptr,head,strlen(head)) == 0)
{
temp = ptr;
ptr+=strlen(head);
while(*ptr != '\0')
{
if(strncmp(ptr,tail,strlen(tail)) == 0)
{
*(ptr+strlen(tail)) = '\0';
printf("%s\n",temp);
return 0;
}
ptr++;
}
printf("find head not find tail!\n");
break;
}
else
ptr++;
}
return 0;
}
int main()
{
char src[100];
char head[20];
char tail[20];
printf("please input string:\n");
scanf("%s",src);
printf("please input head:\n");
scanf("%s",head);
printf("please input tail:\n");
scanf("%s",tail);
printf("the result:\n");
fun(src,head,tail);
return 0;
}
#include <stdio.h>
#include <string.h>
int fun(char *ptr,char *head,char *tail)
{
char *temp;
while(*ptr != '\0')
{
if(strncmp(ptr,head,strlen(head)) == 0)
{
temp = ptr;
ptr+=strlen(head);
while(*ptr != '\0')
{
if(strncmp(ptr,tail,strlen(tail)) == 0)
{
*(ptr+strlen(tail)) = '\0';
printf("%s\n",temp);
return 0;
}
ptr++;
}
printf("find head not find tail!\n");
break;
}
else
ptr++;
}
return 0;
}
int main()
{
char src[100];
char head[20];
char tail[20];
printf("please input string:\n");
scanf("%s",src);
printf("please input head:\n");
scanf("%s",head);
printf("please input tail:\n");
scanf("%s",tail);
printf("the result:\n");
fun(src,head,tail);
return 0;
}
相关文章推荐
- 题目:输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headha
- Linux_C练习:输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来。提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktai
- 【嵌入式系统学习记录】习题:输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来。比如:帧头和帧尾分别是head和tail 字符串”asdheadhauboiso
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhau
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhaubo
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来.
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来. 提示:帧头和帧尾分别是head和tail 字符串”asdheadhauboisoktail”中headhau
- 输入一个字符串,同时输入帧头和帧尾(可以是多个字符),将该字符串中合法的帧识别出来。
- 题目:输入一个字符串,打印出该字符串中字符的所有排列。例如输入字符串abc,则输出由字符a、b、c所能排列出来的所有字符串abc、acb、bac、bca、cab和cba。
- 输入一个字符串,同时输入帧头和帧尾
- 输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。 结果请按字母顺序输出。
- 编写一个程序,一行行地读取输入行,直至到达文件尾。算出每行输入行的长度,然后把最长的那行打印出来。为了简单起见,你可以假定所有的输入行均不超过1000个字符
- 输入一个字符串 在输入帧头 帧尾 取合法帧 (标志位的使用)
- 输入一个字符串,按字典序打印出该字符串中字符的所有排列。例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba。
- 题目:剔除一个字符中重复的字符,然后按ASCII码值从小到大排列。 例如,输入:abbcccddeeeffgghh 输出:abcdefgh 注意:1、剔除是整个字符串中重复的字符,而不是连续的字符 2
- 编写一个程序,一行行地读取输入行,直至到达文件尾。算出每行输入行的长度,然后把最长的那行打印出来。为了简单起见,你可以假定所有的输入行均不超过1000个字符