69,377
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <string.h>
#define SEPCHARS "\"<;>"
int main(void)
{
char *word; //存放单词
char *hao; //查找最后一个'|'的指针
char b[300]; //从文件读取一行存放在b数组中
char a[300]={0}; //数据转换后存放在a数组中
FILE *frp=fopen("read.txt","r");
FILE *fwp=fopen("write.txt","w+");
while(fgets(b,300,frp)!=NULL)
{
a[0]='\0';
word=strtok(b,SEPCHARS);
while(word!=NULL)
{
if(isdigit(*word))
{
printf("%s\n",word);
strcat(a,word);
strcat(a,"|");
}
word=strtok(NULL,SEPCHARS);
}
hao=strrchr(a,'|');
*hao='\n';
printf("%s",a);
fputs(a,fwp);
}
}
#include <stdio.h>
#include <string.h>
#define BUF_LEN 1024
#define EMAIL_LEN 80
char s[]="\"单身\"<760026313@qq.com>; \"XXD\"<502144951@qq.com>; \"凤凰\"<542307112@qq.com>;\"\" <111@qq.com>;\"\" <222@sina.com.cn>;\"\" <333@yahoo.com>;";
char *p,*q;
int n,k;
char e[EMAIL_LEN];
char b[BUF_LEN];
void main() {
p=s;
q=b;
while (1) {
if (1==sscanf(p,"%*[^<]<%[^>]>%n",e,&n)) {
p+=n;
k=sprintf(q,"%s|",e);
q+=k;
if (q-b>BUF_LEN-EMAIL_LEN) break;
} else break;
}
q[-1]=0;//去掉末尾的|
printf("%s\n",b);
}
运行结果
760026313@qq.com|502144951@qq.com|542307112@qq.com|111@qq.com|222@sina.com.cn|333@yahoo.com
#include <stdio.h>
void getMailbox(char *str)
{
int i = 0, j = 0;
while(str[j] != '\0')
{
if(str[j++] == '<')
{
while(str[j] != '>')
str[i++] = str[j++];
str[i++] = '|';
}
}
str[i-1] = '\0';
}
int main()
{
char str[] = """ <111@qq.com>;"" <222@sina.com.cn>;"" <333@yahoo.com>;";
getMailbox(str);
printf("%s\n", str);
return 0;
}
#include <stdio.h>
int main(void)
{
char a[300];
char b[300] = "\"单身\"<760026313@qq.com>; \"XXD\"<502144951@qq.com>; \"凤凰\"<542307112@qq.com>";
sscanf(b, "%*[^<]%*c%[^>]s", a);
printf("%s\n", a);
return 0;
}
// output : 760026313@qq.com
owenliang@linux-7lsl:~/csdn/src> echo "\"单身\"<760026313@qq.com>; \"XXD\"<502144951@qq.com>; \"凤凰\"<542307112@qq.com>" | sed -r 's/[<>]|("[^"]*")//g' | awk -F ";" '{gsub(";"," | ");print;}'
760026313@qq.com | 502144951@qq.com | 542307112@qq.com
owenliang@linux-7lsl:~/csdn/src> echo "\"\"<111@qq.com>;\"\" <222@sina.com.cn>;\"\" <333@yahoo.com>;" | sed -r 's/["<>]//g' | awk -F ";" '{gsub(";"," | ");print;}'
111@qq.com | 222@sina.com.cn | 333@yahoo.com |