Page 1 of 1

fat pading

Posted: Mon Jul 11, 2005 9:49 am
by GLneo
hi all, for any one who doesn't know for fat names, you must convert names as follows:

Code: Select all

"file.txt" -> "file    txt"
so that before the dot has 8 places aftor 3.

my code simply copys letter per letter, if a dot what ever is left is "spaced":

Code: Select all

unsigned char *fat_pad(unsigned char *str)
{
    int pc = 0, sc = 0; // pc = paded count, sc = str count
    while(str[sc] != '\0') // while more left in string
    {
        if(str[sc] == '.') // if dot
        {
            for(; pc < 8; pc++) // untill 8
                paded[pc] = ' '; // space pad
            sc++; // jump over dot
        }    
        paded[pc] = str[sc]; // reg letter just transfer
        pc++; sc++; // move 1 letter ahead
    }
    return paded; // return new string
}
when i run it, it kills the system???

Re:fat pading

Posted: Mon Jul 11, 2005 12:39 pm
by distantvoices
hm. where do you declare "paded" - that array you copy the passed string to? and where do you acquire the memory needed for "paded"

I daresay that's the first problem I see at a short glance. Fix it, give it a try once more.

Re:fat pading

Posted: Mon Jul 11, 2005 12:51 pm
by GLneo
paded is a globle variable so i dont pass internal variable

EDIT: nevermine you were right, thx