刚毕业,因为从事软件嵌入式开发,所以想提高一下c的基础,程序可能有点幼稚,有不对的希望大神指教。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int num = 2;
int count = 0;
char src[100];
char buff[100];
char *pstr = NULL;
char *qstr = NULL;
char *head = NULL;
char *temp = NULL;
gets(src);
pstr = src;
while(*pstr != '\0')
{
qstr = pstr + 2;
while(*qstr != '\0')
{
head = pstr;
temp = qstr;
while(*pstr == *qstr)
{
pstr++;
qstr++;
count++;
}
if(count >= num)
{
num = count;
count = 0;
memset(buff,0,sizeof(buff));
strncpy(buff,temp,num);
}
{
count = 0;
}
pstr = head;
qstr = temp;
qstr++;
}
pstr++;
}
printf("%s\n",buff);
system("pause");
return 0;
}
}
本文分享了一个简单的C语言程序,用于演示如何实现字符串中特定模式的查找。通过双重循环遍历源字符串,比较并记录匹配字符的数量,最终找出最长的重复模式。

被折叠的 条评论
为什么被折叠?



