Advertisement

sscanf Question

Started by July 16, 2000 08:41 PM
7 comments, last by Esap1 24 years, 5 months ago
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
Back to TOP
Advertisement
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<i> = 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
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.
Hasn''t this one already come up? sscanf(in, "\"[^\"]", out);
Yes, it can. To do so, use this:
    sscanf(tt, "\"%[^\"]\"", tt_new);    


// CHRIS
// CHRIS [win32mfc]
Advertisement
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
// CHRIS [win32mfc]
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.
/Mankind gave birth to God.

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



So I did. Thanks for catching it.

This topic is closed to new replies.

Advertisement