forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using sscanf() to extract strings

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Fri Jan 12, 2007 10:50 am    Post subject: Using sscanf() to extract strings Reply with quote

hi everyone,

what i want to do is be able to remove the last character from my c string, now i thought i could do this sscanf(), but its driving me nuts it wasn't working at the start then i added an extra variable called grab and it worked, but it was removing one too many characters, so i changed the variable and now its not working again
here
is my code
Code:
temp = line[linesUsed].data;
int grab = totalChars - 1;
sscanf(temp, "%[grab]s", line[linesUsed].data);
chars--;
totalChars--;
if (chars < 0){linesUsed--; chars = MAX_CHARS;}   

basically what im trying to do is make a backspace function for my program thanks for your help
Back to top
View user's profile Send private message
dot_blank



Joined: 28 Sep 2005
Posts: 498
Location: Brasil

PostPosted: Fri Jan 12, 2007 11:53 am    Post subject: Reply with quote

use the std lib string handling for such things

here is a example file extensions
Code:

#define FILE "some_file.ext"
#define FILE_BASE  "%s/%s"
#define PSP_BASE  "ms0:/PSP/GAME/SOME_GAME/"

char temp[1024];
char *file;

snprintf(temp, 1024, FILE_BASE, PSP_BASE, FILE);
file = strrchr(temp, '.');

// finish this simple problem to familiarize yourself
// with using std lib string handling

_________________
10011011 00101010 11010111 10001001 10111010


Last edited by dot_blank on Fri Jan 12, 2007 12:57 pm; edited 1 time in total
Back to top
View user's profile Send private message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Fri Jan 12, 2007 12:12 pm    Post subject: Reply with quote

mmmm i still dont understand how this will help, isnt what your example is doing is concatenating strings??

sorry im so used to using languages like c++, java and the like that im really having trouble using c style strings as i really never used straight c before so im not really familar with many c functions
Back to top
View user's profile Send private message
kuroneko



Joined: 08 Dec 2005
Posts: 24
Location: Chigasaki, Japan

PostPosted: Fri Jan 12, 2007 1:58 pm    Post subject: Re: Using sscanf() to extract strings Reply with quote

Would this help? I assume line[linesUsed].data is the actual string and temp a char* (ASCII string, no multibyte characters).

Code:
temp = line[linesUsed].data;
if (temp[0]) /* string not empty */
{
    temp[strlen(temp)-1] = '\0';
}
Back to top
View user's profile Send private message
reefbarman



Joined: 08 Jan 2007
Posts: 87
Location: Australia

PostPosted: Sat Jan 13, 2007 12:27 am    Post subject: Reply with quote

that worked b e a utifully thanks
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group