如何删除C中的重复单词 [英] how to remove the duplicate words in C

查看:218
本文介绍了如何删除C中的重复单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条这样的路

I have a path like this

C:\Users\Desktop\new3oct\31oct\Project\Project\\bin\\logsgs"


通过编程,我必须将其转换为此,我应该使用strtok吗?无法理解逻辑,请告诉


By programming i have to convert it to this,should i use strtok? Not getting the logic,please tell

"C:\Users\Desktop\new3oct\31oct\Project\bin\\logsgs"

推荐答案

您没有" t指定是只显示所有重复的单词,还是只显示连续的重复单词.

假设使用后一种选项,则需要拆分路径以使斜线之间的单词相同.您可以使用strtok进行此操作,但是自己扫描字符串并不困难:搜索反斜杠,如果找到反斜杠,则继续搜索下一个非反斜杠字符.

当您搜索一个新单词时,请确保保留先前找到的单词.然后比较两者.复制时,请复制单词和反斜杠,除非有重复的情况.
You didn''t specify if you need to suppress all duplicate words or just the consecutive duplicate words.

Assuming the latter option, you need to split the path to get the words between the slashes. You can do this with strtok, but scanning the string yourself is not much harder: search for a backslash and if you find one, continue the search for the next non-backslash character.

When you search a new word, make sure to keep a trace of the previous you found. Then compare both. Copy the words and backslashes as you go, except in the case of a duplicate.


这篇关于如何删除C中的重复单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆