#### Archived

This topic is now archived and is closed to further replies.

# sscanf Question

This topic is 6580 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

If I had this in a array of chars: "c:\hi.txt" and I just wanted: c:\hi.txt How would I use sscanf to take out the Quotes. I dont know the switch for quotes. Could someone help, thanks

##### Share on other sites
for what possible purpose could taking out the quotes serve ?
But any way here it is

  char name[30];// somewhere in here name = "C:\hi.txt" through user input or you// set itint length = strlen(name);for (int i = 0; i < length-1; i++){ name = name[i+1];}name[length-2] = name[length-1];name[length-1] = '\0';

viola

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Edited by - ncsu121978 on July 16, 2000 10:58:52 PM

##### Share on other sites
I thought you could do it using sscanf. Well, that function you wrote only took the first letter out. It kinda looks like the one I wrote.
But using sscanf() would be much easier.

##### Share on other sites
Hasn''t this one already come up? sscanf(in, "\"[^\"]", out);

##### Share on other sites
Yes, it can. To do so, use this:
  sscanf(tt, "\"%[^\"]\"", tt_new);

// CHRIS

##### Share on other sites
Heh.. FordPrefect and I seemed to have answered at almost the same time, with (almost) the same answer.

Unfortunately, his won't work. He forgot to include the '%' sign before the "[" character.

Attention to detail... Tsk-Tsk...

// CHRIS

Edited by - win32mfc on July 16, 2000 12:09:58 AM

##### Share on other sites
Hi,

To get rid of the last ''"'':
Why don''t you just use something like this?
array[strlen(name)-1] = ''\0'';

Or if you have a odd name like this: "c:\data.txt"morewords
(Where the quotationmark is inside the name)
Just search for the ''\"'' in array and replace it with something appropriate.

/Mankind gave birth to God.

##### Share on other sites

> He forgot to include the ''%'' sign before the "[" character.

So I did. Thanks for catching it.

1. 1
2. 2
3. 3
Rutin
17
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631788
• Total Posts
3002355
×