aout 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const inquirer = require("inquirer");
6
+
7
+ const templatesDir = path.join(__dirname, "..", "templates");
8
+ const currentDir = process.cwd();
9
+
10
+ function getTemplates() {
11
+ return fs.readdirSync(templatesDir).filter(file =>
12
+ fs.statSync(path.join(templatesDir, file)).isFile()
13
+ );
14
+ }
15
+
16
+ async function run() {
17
+ const templates = getTemplates();
18
+
19
+ if (templates.length === 0) {
20
+ console.log("No templates found.");
21
+ return;
22
+ }
23
+
24
+ const { file } = await inquirer.prompt([
25
+ {
26
+ type: "list",
27
+ name: "file",
28
+ message: "Select a file to copy:",
29
+ choices: templates
30
+ }
31
+ ]);
32
+
33
+ const source = path.join(templatesDir, file);
34
+ const destination = path.join(currentDir, file);
35
+
36
+ if (fs.existsSync(destination)) {
37
+ console.log("File already exists in this folder.");
38
+ return;
39
+ }
40
+
41
+ fs.copyFileSync(source, destination);
42
+ console.log("Copied:", file);
43
+ }
44
+
45
+ run();
package/package.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "aout",
3
+ "version": "1.0.0",
4
+ "description": "CLI tool for react projects",
5
+ "bin": {
6
+ "aout": "bin/cli.js"
7
+ },
8
+ "type": "commonjs",
9
+ "files": [
10
+ "bin",
11
+ "templates"
12
+ ],
13
+ "dependencies": {
14
+ "inquirer": "^8.2.0"
15
+ }
16
+ }
@@ -0,0 +1,85 @@
1
+ /*a6p2.c Write a menu driven program to perform the following operations on two strings using pointer and without using library or built -in string function.
2
+ a) Copy b) Compare [20 marks]*/
3
+ #include <stdio.h>
4
+
5
+ int main()
6
+ {
7
+ char str1[100], str2[100];
8
+ int choice, result;
9
+
10
+ /* Function declarations inside main */
11
+ void copyString(char *, char *);
12
+ int compareString(char *, char *);
13
+
14
+ printf("Enter first string: ");
15
+ fgets(str1, 100, stdin);
16
+
17
+ printf("Enter second string: ");
18
+ fgets(str2, 100, stdin);
19
+
20
+ do
21
+ {
22
+ printf("\n--- MENU ---\n");
23
+ printf("1. Copy String\n");
24
+ printf("2. Compare String\n");
25
+ printf("3. Exit\n");
26
+ printf("Enter your choice: ");
27
+ scanf("%d", &choice);
28
+ getchar(); // clears newline from buffer
29
+
30
+ switch(choice)
31
+ {
32
+ case 1:
33
+ copyString(str1, str2);
34
+ printf("After copying, second string is: %s\n", str2);
35
+ break;
36
+
37
+ case 2:
38
+ result = compareString(str1, str2);
39
+ if(result == 0)
40
+ printf("Both strings are equal\n");
41
+ else
42
+ printf("Strings are not equal\n");
43
+ break;
44
+
45
+ case 3:
46
+ printf("Exiting program...\n");
47
+ break;
48
+
49
+ default:
50
+ printf("Invalid choice!\n");
51
+ }
52
+
53
+ } while(choice != 3);
54
+
55
+ return 0;
56
+ }
57
+
58
+ /* Function to copy one string into another using pointers */
59
+ void copyString(char *src, char *dest)
60
+ {
61
+ while(*src != '\0')
62
+ {
63
+ *dest = *src;
64
+ src++;
65
+ dest++;
66
+ }
67
+ *dest = '\0';
68
+ }
69
+
70
+ /* Function to compare two strings using pointers */
71
+ int compareString(char *s1, char *s2)
72
+ {
73
+ while(*s1 != '\0' && *s2 != '\0')
74
+ {
75
+ if(*s1 != *s2)
76
+ return 1;
77
+ s1++;
78
+ s2++;
79
+ }
80
+
81
+ if(*s1 == '\0' && *s2 == '\0')
82
+ return 0;
83
+ else
84
+ return 1;
85
+ }