| View previous topic :: View next topic |
| Author |
Message |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Jan 12, 2007 10:50 am Post subject: Using sscanf() to extract strings |
|
|
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 |
|
 |
dot_blank

Joined: 28 Sep 2005 Posts: 498 Location: Brasil
|
Posted: Fri Jan 12, 2007 11:53 am Post subject: |
|
|
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 |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Fri Jan 12, 2007 12:12 pm Post subject: |
|
|
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 |
|
 |
kuroneko
Joined: 08 Dec 2005 Posts: 24 Location: Chigasaki, Japan
|
Posted: Fri Jan 12, 2007 1:58 pm Post subject: Re: Using sscanf() to extract strings |
|
|
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 |
|
 |
reefbarman
Joined: 08 Jan 2007 Posts: 87 Location: Australia
|
Posted: Sat Jan 13, 2007 12:27 am Post subject: |
|
|
| that worked b e a utifully thanks |
|
| Back to top |
|
 |
|