TGViewer
Linux - Reddit Linux - Reddit @r_linux · 1.05K subscribers
Post #43121 26
{

wait(NULL);

}

}

}

else if (strcmp(pkgmn, "dnf") == 0) {

while(1) {

char dnf[512\];

printf("pkg install: ");

fgets(dnf, sizeof(dnf), stdin);

dnf[strcspn(dnf, "\\n")\] = '\\0';

pid_t pid = fork();

if (pid < 0) {

perror("failed pid");

}

else if (pid == 0) {

char *args[\] = {"sudo", "dnf", "install", dnf, NULL};

execvp(args[0\], args);

perror("failed execvp");

exit(1);

}

else {

wait(NULL);

}

}

}

else if (strcmp(pkgmn, "pacman") == 0) {

char pacman[512\];

printf("pkg install: ");

fgets(pacman, sizeof(pacman), stdin);

pacman[strcspn(pacman, "\\n")\] = '\\0';

pid_t pid = fork();

if (pid < 0) {

perror(" failed pid");

}

else if (pid == 0) {

char *args[\] = {"sudo", "pacman", "-S", pacman, NULL};

execvp(args[0\], args);

perror("failed execvp");

exit(1);

}

else {

wait(NULL);

}

}

}

void c_cpp_helper(void)

{

int choice;

do {

system("clear");

printf("C vs C++ QUICK HELPER & COMPARISON\\n\\n");

printf("1.Learn about if-else in C vs C++\\n");

printf("2.Compare I/O (printf/scanf vs cin/cout)\\n");

printf("3.C99 stdbool.h vs C++ Native Bool\\n");

printf("4.Memory Management (malloc/free vs new/delete)\\n");

printf("5.Back / Exit\\n\\n");

printf("Enter your choice: ");

if (scanf("%d", &choice) != 1) {

while (getchar() != '\\n');

continue;

}

system("clear");

switch (choice) {

case 1:

printf("IF-ELSE IN C VS C++\\n\\n");

printf("In C:\\n");

printf(" Uses integer values to evaluate conditions.\\n");

printf(" 0 means FALSE, any NON-ZERO value means TRUE.\\n");

printf(" Example: if (1) { /* Always runs */ }\\n\\n");

printf("In C++:\\n");

printf(" Has native 'bool' type with 'true' and 'false'.\\n");

printf(" Conditions like if (expr) still implicitly convert numbers to bool.\\n");

break;

case 2:

printf("PRINTF/SCANF (C) VS CIN/COUT (C++)\\n\\n");

printf("C (printf / scanf):\\n");

printf(" Pure functions inside <stdio.h>.\\n");

printf(" Requires explicit format specifiers: %%d, %%s, %%f, %%p.\\n");

printf(" Minimal memory footprint, perfect for lightweight CLI tools.\\n\\n");

printf("C++ (cin / cout):\\n");

printf(" Stream objects inside <iostream>.\\n");

printf(" Automatically detects data types via operator overloading (<<, >>).\\n");

printf(" Convenient, but increases binary size.\\n");

break;

case 3:

printf("BOOLEAN TYPES\\n\\n");

printf("In C:\\n");

printf(" C89/C90 has no native bool type.\\n");

printf(" Since C99, you must include <stdbool.h> to use 'bool', 'true', 'false'.\\n\\n");

printf("In C++:\\n");

printf(" 'bool', 'true', and 'false' are built-in keywords.\\n");

break;

case 4:

printf("MEMORY MANAGEMENT\\n\\n");

printf("In C:\\n");

printf(" Uses malloc(), calloc(), realloc() for Heap allocation.\\n");

printf(" Manual memory cleanup required using free() to prevent leaks.\\n\\n");

printf("In C++:\\n");

printf(" Uses 'new' and 'delete' (or 'delete[\]').\\n");

printf(" Supports RAII and Smart Pointers (unique_ptr, shared_ptr) for safety.\\n");

break;

case 0:

printf("Exiting C/C++ Helper.\\n");

break;

default:

printf("Invalid choice!\\n");

break;

}

if (choice != 0) {

printf("\\n[Press Enter to continue...\]");

while (getchar() != '\\n');

getchar();

}

} while (choice != 0);

}

void rm(void)

{

char rm_file[80\];

printf("file want to remove ? ");

fgets(rm_file, sizeof(rm_file), stdin);

rm_file[strcspn(rm_file, "\\n")\] = '\\0';

char sure[10\];

printf("Sure ? Y/n : ");

fgets(sure, sizeof(sure), stdin);

sure[strcspn(sure, "\\n")\] = '\\0';

if (strcmp(sure, "y") == 0 ||
More from @r_linux
  1. Oct 5, 2026NVIDIA security bulletin for Sept 30 notes many GPU issues https://www.gamingonlinux.com/2…
  2. Oct 5, 2026ShadeVk - A cross-platform pixel shader viewer for Vulkan, written in C23. https://redd.it…
  3. Oct 5, 2026hothello: A different piece of animated, colourful ASCII art every time you log in with a…
  4. Oct 5, 2026Linux Plumbers Conference, 2026 ...schedules https://lpc.events/event/20/sessions/246/#202…
  5. Oct 5, 2026Part of Cern to debian Maybe I missed such a discussion here but, Cern used to be a very l…
  6. Oct 5, 2026I built a watchdog for GNOME's file indexer because LocalSearch/Tracker kept freezing my 8…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →