
I'm annoyed because you are trying to program in a new language without learning it.JoostinOnline: I'm not sure why you are getting so upset with me for trying.

Because sizeof(x[0]) isn't always 1, dumbass. It depends on the variable type. That macro will show the length of any array, whether it is of chars or a ints. It's pre-processed too.Your so-called optimization is terrible, how is "sizeof(x)/sizeof(x[0])" useful for char arrays (where sizeof(x[0]) is known to be 1)

Pretty sure you're just trolling right now, but I'll give you the benefit of the doubt and assume you're just an idiot.x never changes the size of its elements because it's declared as a char array; it says so right there in the code. sizeof(x) does exactly the same thing.
Nearly all bounds checking functions (snprintf, strncat, etc.) are for char arrays, using anything more than sizeof()-1 is a waste of space except when the array size isn't known; in those cases your code will fail spectacularly anyway.
void find_size(short *buffer) {
printf("number of elements in buffer: %u\n", MAX_ELEMENTS(buffer));
}

You're just trolling now. Not all arrays are char arrays, and you know that.

Of course it's only for predefined sizes. Sizes can change though, and if the function is big enough, it's easy to forget to change the parameters of a loop. This doesn't make the binary bigger or slow anything down, it just eliminates the possibility of accidentally forgetting to change a parameter.he is clearly not trolling and neither he said all arrays are char array
BUT in the example you gave, array is declared as a char array so your macro is indeed pointless in that case and in other cases, nobody should use it either because it's bad coding, you cannot find the size of an array like that unless the size is already known (i.e it does not work with array pointers, only locally declared array), which makes it even more useless after all.
I was simply making a suggestion to Foxi.So i don't know if the worst thing is that you are trying to help and correct someone with bad tips or that you are convinced that people are trolling you when they are only correctingyour obvious coding mistakes ^^
Are you talking to the OP now?As for the initial problem you are trying to solve, the best way is to look at usbStorage implementation in libogc: the function you want to use needs a pointer to an INITIALIZED usb device handler, you cannot just declare an empty device handler structure and expect it to work magically. It is not clear to me how you are supposed to do that but the answer is surely in usbstorage.c within libogc, which uses this function. But as said before, that function does NOT gives you the drive capacity but apparently the sector (block unit if you prefer) size. Again, this comes from a quick review of the code in libogc, which is how you should do to try to figure things out, not random clueless guessing...
I'm annoyed because you are trying to program in a new language without learning it.
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <ogc/usbstorage.h>
#include <iostream>
#include <string>
#include <string.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <fat.h>
#include <dirent.h>
#include <math.h>
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
int statvfs(const char *path, struct statvfs *buf);
int fstatvfs(int fd, struct statvfs *buf);
int round_int( double r ) {
return (r > 0.0) ? (r + 0.5) : (r - 0.5);
}
int fat_shit()
{
if (!fatInitDefault()) {
printf("Unable to initialize FAT subsystem, exiting. \n \n");
exit(0);
}
else {
printf("Successfully initialized FAT subsystem. \n \n");
}
const uint GB = (1024 * 1024) * 1024;
struct statvfs buffer;
// usb:/ usb2:/ usb3:/ sd:/
statvfs("sd:/", &buffer);
const double total = (double)buffer.f_blocks * buffer.f_frsize / GB;
const double available = (double)buffer.f_bfree * buffer.f_frsize / GB;
const double used = total - available;
const double usedPercentage = ceil(used / total * 100);
const double availablePercentage = ceil(available / total * 100);
int usedPercentageRounded = round_int(usedPercentage);
int availablePercentageRounded = round_int(availablePercentage);
printf("Used Space: %u", usedPercentageRounded); printf("%% \n \n");
printf("Free Space: %u", availablePercentageRounded); printf("%% \n \n");
fatUnmount(0);
return 0;
}
int my_sleep(int s)
{
usleep(s * 1000000);
return 0;
}
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
// Initialise the video system
VIDEO_Init();
// This function initialises the attached controllers
WPAD_Init();
// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);
// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);
// Make the display visible
VIDEO_SetBlack(FALSE);
// Flush the video register changes to the hardware
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
// The console understands VT terminal escape codes
// This positions the cursor on row 2, column 0
// we can use variables for this with format codes too
// e.g. printf ("\x1b[%d;%dH", row, column );
printf("\x1b[2;0H");
printf("RiCK420 has taken over your Wii! \n \n");
my_sleep(3);
printf("...Just Kidding! Please wait patiently! \n \n");
//Fat Shit
fat_shit();
// Exiting Routine
printf("Process complete, press [HOME] to EXIT or wait 30 seconds. \n \n");
my_sleep(30);
printf("...EXITING! \n");
exit(0);
while(1) {
// Call WPAD_ScanPads each loop, this reads the latest controller states
WPAD_ScanPads();
// WPAD_ButtonsDown tells us which buttons were pressed in this loop
// this is a "one shot" state which will not fire again until the button has been released
u32 pressed = WPAD_ButtonsDown(0);
// We return to the launcher application via exit
if ( pressed & WPAD_BUTTON_HOME ) { printf("...EXITING! \n"); exit(0);}
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <wiiuse/wpad.h>
#include <ogc/usbstorage.h>
#include <iostream>
#include <string>
#include <string.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <fat.h>
#include <dirent.h>
#include <math.h>
static void *xfb = NULL;
static GXRModeObj *rmode = NULL;
int statvfs(const char *path, struct statvfs *buf);
int fstatvfs(int fd, struct statvfs *buf);
int round_int( double r ) {
return (r > 0.0) ? (r + 0.5) : (r - 0.5);
}
int fat_shit(std::string drive)
{
if (!fatInitDefault()) {
printf("Unable to initialize FAT subsystem, exiting. \n \n");
exit(0);
}
else {
printf("Successfully initialized FAT subsystem. \n \n");
}
const uint GB = (1024 * 1024) * 1024;
struct statvfs buffer;
// usb2:/ usb3:/ sd:/ (string drive) ?
statvfs(drive, &buffer);
const double total = (double)buffer.f_blocks * buffer.f_frsize / GB;
const double available = (double)buffer.f_bfree * buffer.f_frsize / GB;
const double used = total - available;
const double usedPercentage = ceil(used / total * 100);
const double availablePercentage = ceil(available / total * 100);
int usedPercentageRounded = round_int(usedPercentage);
int availablePercentageRounded = round_int(availablePercentage);
printf("Used Space: %u", usedPercentageRounded); printf("%% \n \n");
printf("Free Space: %u", availablePercentageRounded); printf("%% \n \n");
fatUnmount(0);
return 0;
}
int my_sleep(int s)
{
usleep(s * 1000000);
return 0;
}
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
// Initialise the video system
VIDEO_Init();
// This function initialises the attached controllers
WPAD_Init();
// Obtain the preferred video mode from the system
// This will correspond to the settings in the Wii menu
rmode = VIDEO_GetPreferredMode(NULL);
// Allocate memory for the display in the uncached region
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
// Initialise the console, required for printf
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
// Set up the video registers with the chosen mode
VIDEO_Configure(rmode);
// Tell the video hardware where our display memory is
VIDEO_SetNextFramebuffer(xfb);
// Make the display visible
VIDEO_SetBlack(FALSE);
// Flush the video register changes to the hardware
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
// The console understands VT terminal escape codes
// This positions the cursor on row 2, column 0
// we can use variables for this with format codes too
// e.g. printf ("\x1b[%d;%dH", row, column );
printf("\x1b[2;0H");
printf("RiCK420 has taken over your Wii! \n \n");
my_sleep(3);
printf("...Just Kidding! Please wait patiently! \n \n");
//Fat Shit
std::string d;
d = "sd:/";
fat_shit(d);
// Exiting Routine
printf("Process complete, press [HOME] to EXIT or wait 30 seconds. \n \n");
my_sleep(30);
printf("...EXITING! \n");
exit(0);
while(1) {
// Call WPAD_ScanPads each loop, this reads the latest controller states
WPAD_ScanPads();
// WPAD_ButtonsDown tells us which buttons were pressed in this loop
// this is a "one shot" state which will not fire again until the button has been released
u32 pressed = WPAD_ButtonsDown(0);
// We return to the launcher application via exit
if ( pressed & WPAD_BUTTON_HOME ) { printf("...EXITING! \n"); exit(0);}
// Wait for the next frame
VIDEO_WaitVSync();
}
return 0;
}
