Archived

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

sscanf Question

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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 it


int 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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites