Welcome back guys,
I am really sorry for another break here.
But now i am back and let's get on towards the output of our last program i.e where we left last time. So let me share the program below and those who want to take the challenge to find the output can go and see the blog shared 6 days ago.
There is also the explanation of the same program in my last blog so people can go through it as well.
The Program :
You can copy the code from above :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
void reshuffleString(char *str) {
int length = strlen(str);
for (int i = 0; i < length - 1; i++) {
int j = i + rand() % (length - i);
char temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
void reverseString(char *str) {
int length = strlen(str);
for (int i = 0; i < length / 2; i++) {
char temp = str[i];
str[i] = str[length - i - 1];
str[length - i - 1] = temp;
}
}
void deleteRandomChars(char *str, int numToDelete) {
int length = strlen(str);
if (numToDelete >= length) {
str[0] = '\0'; // Delete the entire string
} else {
for (int i = 0; i < numToDelete; i++) {
int randomIndex = rand() % length;
for (int j = randomIndex; j < length - 1; j++) {
str[j] = str[j + 1];
}
str[length - 1] = '\0';
length--;
}
}
}
int main() {
srand(time(NULL)); // Initialize random seed
char input[100];
printf("Enter a string: ");
fgets(input, sizeof(input), stdin);
input[strcspn(input, "\n")] = '\0'; // Remove the newline character
printf("Options:\n");
printf("1. Reshuffle the string\n");
printf("2. Reverse the string\n");
printf("3. Delete random characters\n");
int option;
printf("Select an option (1/2/3): ");
scanf("%d", &option);
switch (option) {
case 1:
reshuffleString(input);
break;
case 2:
reverseString(input);
break;
case 3:
int numToDelete;
printf("Enter the number of characters to delete: ");
scanf("%d", &numToDelete);
deleteRandomChars(input, numToDelete);
break;
default:
printf("Invalid option\n");
return 1;
}
printf("Modified string: %s\n", input);
return 0;
}
Let us move towards the output of our program now.
There are two more options and i want people to try that themself.
If you also want to learn basics and start your C programming journey then find a teacher today for free on Youtube.
I learnt alot from a teacher who teaches c in hindi and if you are finding someone who teaches in hindi then this person will definitely help you.
I am happy to call myself a trader and small programmer at the same time now.
Happy trading and keep learning what you love.