Alright so i have my array:
unsiged int *arr = (unsigned int*)malloc(200 * sizeof(unsigned int));
Declared like this, and i have wrote a loop that loops through each element of the array and calls a function with the element as its argument, which looks like this:
for (size_t i = 0; i < sizeof(arr) / sizeof(arr[0]); i++) {
sprintf(buffer, "/proc/%zu/cmdline", arr[i]);
printf("/proc/%x/cmdline", arr[0]);
printf("/proc/%zu/cmdline", arr[i]);
checkIfRunning(buffer);
}
the checkIfRunning function contains:
void checkIfRunning(char *filepath) {
FILE *fh;
char buf[500];
fh = fopen(filepath, "r");
if (!fh)
exit(1);
My code always exits at exit(1), i get the following (wrong) outputs from both the printf statements:
/proc/bbb07a63/cmdline
/proc/3148905059/cmdline
What am i doing wrong
Please note that i am new to c and i'm sorry if newbie question, also note that the output of printf is different each time, which i assume means its garbage.