C检查重复的字符串项 [英] C Check duplicate string entries
本文介绍了C检查重复的字符串项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要检查,如果在我的文件中有重复条目,在C
示例文件:
的/ proc / PROC1 1000
的/ proc / PROC2 2000
的/ proc / PROC1 3000
我需要解决这样的:
的/ proc / PROC1 1000 3000
的/ proc / PROC2 2000
的路径(的/ proc / proc中*)可以包括空格喜欢:/ proc中的/ proc你好/富
这里我写的东西来处理的/ proc /和它们的PID,但现在我卡在这个问题..
解决方案
的#include<&stdio.h中GT;
#包括LT&;&string.h中GT;诠释主要(无效){
烧焦海峡[] =/ proc中的/ proc你好/ foo的4000;
焦炭路径[256];
炭PID [10];
字符* P; p值= strrchr(STR,'');
的strcpy(PID,P + 1);
* P ='\\ 0';
的strcpy(路径,STR);
的printf(%S \\ n,路径); // / proc中的/ proc你好/富
的printf(%S \\ n,PID); // 4000 返回0;
}
I need to check if in my file there are duplicates entries, in C.
Sample file:
/proc/proc1 1000
/proc/proc2 2000
/proc/proc1 3000
I need to solve like this:
/proc/proc1 1000 3000
/proc/proc2 2000
The path (/proc/proc*) can include spaces likes: /proc/proc hello/foo
Here I wrote something to handle /proc/ and their pids, but now I'm stuck on this problem..
解决方案
#include <stdio.h>
#include <string.h>
int main(void){
char str[]= "/proc/proc hello/foo 4000";
char path[256];
char pid[10];
char *p;
p=strrchr(str, ' ');
strcpy(pid, p+1);
*p='\0';
strcpy(path, str);
printf("%s\n", path);// /proc/proc hello/foo
printf("%s\n", pid);// 4000
return 0;
}
这篇关于C检查重复的字符串项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文